Ordenar en columna en tabla de tipos con ColdFusion ORM
Tengo tres tablas, con la siguiente estructura:
http://dl.dropbox.com/u/2586403/ORMIssues/TableLayout.png
Los tres objetos con los que estoy tratando están aquí:
http://dl.dropbox.com/u/2586403/ORMIssues/Objects.zip
Necesito poder obtener un PartObject y luego extraer todos sus Atributos, ordenados por AttributeName en la tabla Tipos. Aquí están los problemas con los que me encuentro:
No puedo ordenar la propiedad Attributes en PartObject por su propiedad Attribute.AttributeName
No puedo agregar la propiedad Attribute.AttributeName a la entidad ObjectAttribute porque recibo un error con respecto a los nombres de columna. Hibernate está poniendo la identificación en el lado equivocado de la unión
Aquí está el archivo de registro de hibernación que muestra la consulta incorrecta
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.
Aquí está la sección ofensiva de la consulta:
from ObjectAttributes objectattr0_
inner join Attributes objectattr0_1_ on objectattr0_.ID=objectattr0_1_.AttributeID
Debería ser:
from ObjectAttributes objectattr0_
inner join Attributes objectattr0_1_ on objectattr0_.AttributeID=objectattr0_1_.ID
La propiedad AttributeName en ObjectAttribute.cfc es la que causa el problema:
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" ;
}
También intenté usar una fórmula para obtener el AttributeName en la entidad ObjectAttribute, de esta manera:
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)";
}
Esto funciona, pero no puedo ordenar por esa columna calculada. Si luego ajusto PartObject.cfc así:
property name="Attributes" cfc="ObjectAttribute" type="array" fkcolumn="ObjectID" fieldtype="one-to-many" orderby="AttributeName";
Recibo los siguientes errores en el registro de 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.
Aquí hay un basurerosin esa propiedad para mostrar que el resto de las relaciones funcionan correctamente:
http://dl.dropbox.com/u/2586403/ORMIssues/Dump.pdf
No tengo idea de cómo solucionar este problema. Cualquier ayuda que pueda proporcionar sería muy apreciada.
Gracias,
Dan