Domanda

Ho tre tabelle, con la seguente struttura:

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

I tre oggetti ho a che fare sono qui:

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

ho bisogno di essere in grado di ottenere un PartObject, e poi tirare tutti i suoi attributi, ordinato in base alla AttributeName nella tabella Tipi. Qui ci sono i problemi che sto funzionando in:

  1. Non posso sorta Gli attributi di proprietà in PartObject dal suo Attribute.AttributeName proprietà

  2. Non posso aggiungere la proprietà Attribute.AttributeName all'entità ObjectAttribute perché ricevo un errore su nomi di colonna. Hibernate sta mettendo l'ID sul lato sbagliato del join

Ecco il file di log di ibernazione che mostra il cattivo di query

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. 

Ecco la parte incriminata della query:

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

Dovrebbe essere:

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

La proprietà AttributeName sul ObjectAttribute.cfc è quello che causa il 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" ; 
} 

Ho provato anche utilizzando una formula per ottenere l'AttributeName sull'entità ObjectAttribute, in questo modo:

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)";
}

Questo funziona, ma non posso ordina per quella colonna calcolata. Se io quindi regolare PartObject.cfc in questo modo:

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

Ottengo i seguenti errori nel registro 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.

Ecco una discarica senza che la proprietà per mostrare che il resto dei rapporti funzionano correttamente:

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

Non ho idea di come risolvere questo problema. Qualsiasi aiuto è possibile fornire sarebbe molto apprezzato.

Grazie,

Dan

È stato utile?

Soluzione

ho risolto questo con l'aiuto di Sam, attraverso la creazione di un metodo nel mio servizio che ha restituito gli elementi nell'ordine che volevo. Ho appena usato ORMExecuteQuery per ottenere gli elementi nel giusto ordine, e se non ci fossero elementi, appena tornato una matrice vuota.

L'ultimo metodo si presentava così, in cui specifiche sono impostate direttamente in oggetto nell'ordine li voglio:

/**
@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;
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top