我有三张桌子,具有以下结构:

http://dl.dropbox.com/u/2586403/ormissues/tablelelayout.png

我要处理的三个对象在这里:

http://dl.dropbox.com/u/2586403/ormissues/objects.zip

我需要能够获取一个partObject,然后拉出其所有属性,并由类型表中的属性元素排序。这是我遇到的问题:

  1. 我无法通过其属性为partoBject中的属性属性。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上的属性属性是引起问题的一种:

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实体上获取属性,例如:

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

我不知道如何解决此问题。您可以提供的任何帮助将不胜感激。

谢谢,

有帮助吗?

解决方案

我在Sam的帮助下解决了这一问题,通过在服务中设置一种方法,该方法按照我想要的顺序返回项目。我只是使用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;
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top