I'm using Hibernate 3.5 Native Sql in a Oracle legacy database and mapping my queries in a xml file.
When I am trying to map a entity that has a EmbeddedId like that:
Code:
<return alias="vlr" class="org.domain.myapp.entity.EntityWithEmbeddedId" >
<return-property name="id" >
<return-column name="FIELD_1" />
<return-column name="FIELD_2" />
<return-column name="FIELD_3" />
<return-column name="FIELD_4" />
</return-property>
...
Hibernates retrieve the values but in the wrong properties. The debug shows this
Code:
14:50:12,296 TRACE [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-4) Processing result set
14:50:12,297 DEBUG [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-4) Result set row: 0
14:50:12,298 TRACE [org.hibernate.type.descriptor.sql.BasicExtractor] (http-localhost/127.0.0.1:8080-4) Found [19] as column [FIELD_1]
14:50:12,300 TRACE [org.hibernate.type.descriptor.sql.BasicExtractor] (http-localhost/127.0.0.1:8080-4) Found [199] as column [FIELD_2]
14:50:12,301 TRACE [org.hibernate.type.descriptor.sql.BasicExtractor] (http-localhost/127.0.0.1:8080-4) Found [4] as column [FIELD_3]
14:50:12,302 TRACE [org.hibernate.type.descriptor.sql.BasicExtractor] (http-localhost/127.0.0.1:8080-4) Found [201504] as column [FIELD_4]
14:50:12,304 DEBUG [org.hibernate.loader.Loader] (http-localhost/127.0.0.1:8080-4) Result row: EntityKey[org.domain.myapp.entity.EntityWithEmbeddedId#component[FIELD_4,FIELD_1,FIELD_3,FIELD_2]{field4=19, field1=199, field2=201504, field3=4}]
I changed the order of the fields to reflect the EntityKey but I'd like to know how hibernate determines the entry order of the fields of a EmbeddedId.
This is my EmbeddedId's class
Code:
@SuppressWarnings("serial")
@Embeddable
public class MyEmbeddedId implements java.io.Serializable {
private Long field1;
private Long field2;
private Long field3;
private Long field4;
//Getters and Setters
}
And this is how a use in the EntityWithEmbeddedId
Code:
......
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "field1", column = @Column(name = "FIELD_1", nullable = false, scale = 0)),
@AttributeOverride(name = "field2", column = @Column(name = "FIELD_2", nullable = false, scale = 0)),
@AttributeOverride(name = "field3", column = @Column(name = "FIELD_3", nullable = false, scale = 0)),
@AttributeOverride(name = "field4", column = @Column(name = "FIELD_4", nullable = false, scale = 0)) })
@NotNull
public MyEmbeddedId getId() {
return this.id;
}
......