gpt4 book ai didi

hibernate - 使用 ColdFusion ORM 对类型表中的列进行排序

转载 作者:行者123 更新时间:2023-12-03 22:46:09 25 4
gpt4 key购买 nike

我有三个表,结构如下:

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

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

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

我需要能够获得一个 PartObject,然后提取它的所有属性,按类型表中的 AttributeName 排序。以下是我遇到的问题:

  • 我无法按 PartObject 中的 Attributes 属性对其进行排序
    Attribute.AttributeName 属性
  • 我无法将 Attribute.AttributeName 属性添加到 ObjectAttribute 实体,因为我收到有关列名称的错误。 Hibernate 将 ID 放在连接的错误一侧

  • 这是显示错误查询的 hibernate 日志文件
    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

    我不知道如何解决这个问题。您能提供的任何帮助将不胜感激。

    谢谢,

    最佳答案

    我在 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;
    }
    }

    关于hibernate - 使用 ColdFusion ORM 对类型表中的列进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3945734/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com