0

新しいプロジェクトで Hibernate を使い始めたばかりですが、最初のエンティティでエラーが発生しました。

私のスキーマは現在、大陸と国という 2 つのテーブルだけであり、国には大陸 ID 外部キーがあります。

大陸エンティティを呼び出すコードを実行しようとすると、空白のページが表示されます。すべての処理が停止しますが、エラーは表示されません。MXUnit を介してコードを実行すると、実際にエラーが発生します。エラーメッセージは単純Could Not Load an Entity: [continent#1]です。例外の原因はorg.hibernate.exception.SQLGrammarException. それは私が得るすべてです。

私の実際のエンティティコードは次のとおりです。

大陸.cfc

component tablename='continents' persistent=true output=false{
    property name='id' type='numeric' fieldtype='id' datatype='integer';
    property name="name" type='string' length='45';
    property name='bonus' type='numeric';
    property name='countries' type='array' fieldtype='one-to-many' cfc='Country' singularname='country' inverse='true' fkcolumn='continentid' cascade='all-delete-orphan'; 

    public Country function init(string name='', numeric bonus=0){
        setName(Arguments.name);
        return this;
    }
}

国.cfc

component tablename='countries' persistent=true output=false{
    property name='id' type='numeric' fieldtype='id' datatype='integer' generator="identity";
    property name="name" type='string' length='45';
    property name='continent' fieldtype='many-to-one' fkcolumn='continentid' cfc='Continent' missingRowIgnored=true;

    public Country function init(string name=''){
        setName(Arguments.name);
        return this;
    }
}

そして、メソッドを呼び出すコード。ColdSpring Bean にあります

ContinentBean.cfc

component {
    property name="continent" type="any";

    public any function init(any continent=''){
        if(len(Arguments.continent))setContinent(Arguments.continent);
        return this;
    }

    public any function getContinent(){
        return continent;
    }
    public void function setContinent(numeric continent){
        continent = EntityLoad('Continent', Arguments.continent, true);
    }

    public void function setMapService(mapService){variables.instance['mapService'] = Arguments.mapService;}
    public any function getMapService(){return variables.instance['mapService'];}
}

私が理解できるエラー メッセージに関する実際の情報を見つけることができなかったので、これは単に無効な構文である可能性があります。

4

5 に答える 5

4

問題は、オブジェクトにマップされるテーブル名を指定するために間違った属性を使用していたことです。属性は table='' にする必要があるため、休止状態のオブジェクトは次のようになります。

大陸.cfc

component table='continents' persistent=true output=false{
}

国.cfc

component table='countries' persistent=true output=false{
}
于 2011-06-01T13:23:41.813 に答える
1

テーブル構造がJavaクラスにマッピングされているものと異なる場合があります。

于 2012-11-21T12:11:09.520 に答える
0

あなたのDBエンジンは何ですか? orm アプリケーションの構成を確認できますか?

個人的には、プロパティ'datatype'を見たことがなく、ドキュメントにも見つかりませんでした。'sqlType'データ型を強制したい場合に使用することをお勧めします。通常、私は datetime でそれを使用します:

property name="creationDateTime" type="date" sqltype="datetime";

sqltype="datetime"では不十分なので明記しなければなりtype="date"ません。

于 2011-06-01T08:20:12.323 に答える
0

ID構成にデータ型が明示的に指定されて いることを確認してください。

たとえば、次のように変更します。

<id name="id" column="ID"/>

これに:

<id name="id" column="ID" type="java.lang.Long"/>
于 2016-08-12T10:52:31.127 に答える
0

データベース スキーマはどのように見えますか? オブジェクトのデータ型がデータモデルのデータ型と一致しない場合に、SQL Grammer の例外がスローされるのを見てきました。

于 2011-06-01T00:32:16.167 に答える