14

次の構造を持つ 3 つのテーブルがあります。

http://dl.dropbox.com/u/2586403/ORMIssues/TableLayout.png

私が扱っている 3 つのオブジェクトは次のとおりです。

http://dl.dropbox.com/u/2586403/ORMIssues/Objects.zip

PartObject を取得してから、Types テーブルの AttributeName でソートされたすべての属性を取得できるようにする必要があります。私が遭遇している問題は次のとおりです。

  1. PartObject の Attributes プロパティを Attribute.AttributeName プロパティで並べ替えることができません

  2. 列名に関するエラーが発生するため、Attribute.AttributeName プロパティを ObjectAttribute エンティティに追加できません。Hibernate が ID を結合の反対側に配置している

これは、不適切なクエリを示す休止状態のログ ファイルです。

10/14 16:36:39 [jrpp-12] HIBERNATE DEBUG - select objectattr0_.ID as ID1116_, objectattr0_.AttributeValue as Attribut2_1116_, objectattr0_.AttributeID as Attribut3_1116_, objectattr0_1_.AttributeName as Attribut2_1117_ from ObjectAttributes objectattr0_ inner join Attributes objectattr0_1_ on objectattr0_.ID=objectattr0_1_.AttributeID 
10/14 16:36:39 [jrpp-12] HIBERNATE ERROR - [Macromedia] [SQLServer JDBC Driver][SQLServer]Invalid column name 'AttributeID'. 
10/14 16:36:39 [jrpp-12] HIBERNATE ERROR - [Macromedia] [SQLServer JDBC Driver][SQLServer]Statement(s) could not be prepared. 

クエリの問題のあるセクションは次のとおりです。

from ObjectAttributes objectattr0_ 
inner join Attributes objectattr0_1_ on objectattr0_.ID=objectattr0_1_.AttributeID 

そのはず:

from ObjectAttributes objectattr0_ 
inner join Attributes objectattr0_1_ on objectattr0_.AttributeID=objectattr0_1_.ID 

ObjectAttribute.cfc の AttributeName プロパティが問題の原因です。

component  output="false" persistent="true" table="ObjectAttributes" 
{ 
        property name="ID" column="ID" generator="native" type="numeric" ormtype="int" fieldtype="id" unsavedvalue="0" ; 
        property name="AttributeValue" type="string" ; 
        property name="Attribute" fieldtype="many-to-one" cfc="Attribute" fkcolumn="AttributeID" fetch="join"; 
        property name="AttributeName" table="Attributes" joincolumn="AttributeID" ; 
} 

また、次のように、式を使用して ObjectAttribute エンティティの AttributeName を取得しようとしました。

component  output="false" persistent="true" table="ObjectAttributes"
{
    property name="ID" column="ID" generator="native" type="numeric" ormtype="int" fieldtype="id" unsavedvalue="0" ;
    property name="AttributeValue" type="string" ;
    property name="Attribute" fieldtype="many-to-one" cfc="Attribute" fkcolumn="AttributeID" fetch="join";
    property name="AttributeName" type="string" formula="(SELECT A.AttributeName FROM Attributes A WHERE A.ID = AttributeID)";
}

これは機能しますが、その計算列で並べ替えることができません。次に PartObject.cfc を次のように調整すると、次のようになります。

property name="Attributes" cfc="ObjectAttribute" type="array" fkcolumn="ObjectID" fieldtype="one-to-many" orderby="AttributeName";

hibernatesql ログに次のエラーが記録されます。

10/17 16:51:55 [jrpp-0] HIBERNATE DEBUG - select attributes0_.ObjectID as ObjectID2_, attributes0_.ID as ID2_, attributes0_.ID as ID244_1_, attributes0_.AttributeValue as Attribut2_244_1_, attributes0_.AttributeID as Attribut3_244_1_, ((SELECT A.AttributeName FROM Attributes A WHERE A.ID = attributes0_.AttributeID)) as formula25_1_, attribute1_.ID as ID246_0_, attribute1_.AttributeName as Attribut2_246_0_ from ObjectAttributes attributes0_ left outer join Attributes attribute1_ on attributes0_.AttributeID=attribute1_.ID where attributes0_.ObjectID=? order by attributes0_.AttributeName
10/17 16:51:55 [jrpp-0] HIBERNATE ERROR - [Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'AttributeName'.
10/17 16:51:55 [jrpp-0] HIBERNATE ERROR - [Macromedia][SQLServer JDBC Driver][SQLServer]Statement(s) could not be prepared.

残りの関係が適切に機能していることを示すために、そのプロパティのないダンプを次に示します。

http://dl.dropbox.com/u/2586403/ORMIssues/Dump.pdf

この問題を解決する方法がわかりません。あなたが提供できるどんな助けも大歓迎です。

ありがとう、

ダン

4

1 に答える 1

0

サムの助けを借りて、必要な順序でアイテムを返すメソッドをサービスに設定することで、これを解決しました。ORMExecuteQuery を使用してアイテムを正しい順序で取得し、アイテムがない場合は空の配列を返しました。

最終的なメソッドは次のようになりました。仕様は、必要な順序でオブジェクトに直接設定されます。

/**
@hint Gets a SpecGroups object based on ID. Pass 0 to retrieve a new empty SpecGroups object
@ID the numeric ID of the SpecGroups to return
@roles Admin, User
*/
remote ORM.SpecGroups function getSpecGroup(required numeric ID){
    if(Arguments.ID EQ 0){
        return New ORM.SpecGroups();
    }else{
        LOCAL.SpecGroup = EntityLoadByPK("SpecGroups", Arguments.ID);
        LOCAL.SpecsInGroup = ORMExecuteQuery("SELECT Spec FROM SpecInGroup G WHERE G.SpecGroupID = :GroupID ORDER BY SpecLabel, SpecName", {GroupID = LOCAL.SpecGroup.getID()});
        LOCAL.SpecGroup.setSpecifications(LOCAL.SpecsInGroup);
        return LOCAL.SpecGroup;
    }
}
于 2011-09-12T18:57:24.317 に答える