I have a problem which seems to be related to a fix that has been done so far concerning the @OrderBy annotation.
Before I was using the entity-manager-3.2.1.GA and I had no visible problem concerning the orderBy annotation but since I upgrade to entity-manager-3.3.1.GA my code is not working anymore.
I have a bean mapped like this and a getter for a collection of childrens that was working fine before
Code:
@Entity
@Table(name="LEAST_COST_ROUTING_SET")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class LeastCostRoutingSet implements java.io.Serializable, com.bell.cts.dal.Entity<LeastCostRoutingSet> {
...
/**
* Getter for LeastCostRoutingList
* @return The value of LeastCostRoutingList
* @pre None
* @post lResult != null
*/
@OneToMany(mappedBy="leastCostRoutingSet", cascade = {CascadeType.REMOVE}, fetch=FetchType.LAZY)
@Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@OrderBy("id.location asc")
public List<LeastCostRouting> getLeastCostRoutingList() {
return mLeastCostRoutingList;
}
...
the problem with the new version is that when the mapping is executed I catch a NullPointerException, here is the stack trace.
Code:
Exception in thread "main" javax.persistence.PersistenceException: java.lang.NullPointerException
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:258)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at provisioning.TestMappingCollections.<init>(TestMappingCollections.java:143)
at provisioning.TestMappingCollections.main(TestMappingCollections.java:258)
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.annotations.CollectionBinder.buildOrderByClauseFromHql(CollectionBinder.java:851)
at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:608)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:563)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:517)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1269)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:150)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
It seems that using the orderby annotation implys that the persistent class associated with the join point need to be known by hibernate prior to define the association.
This is a problem for me since there is no order specified when the mapping is executed.
Is there something we can do to workaround this situation or it is a bug that need to be notified in JIRA?