-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: OrderBy and association table collections
PostPosted: Mon Feb 06, 2006 5:59 pm 
Newbie

Joined: Fri Jan 13, 2006 7:31 pm
Posts: 3
Greetings,

In section 2.2.5.3.1 of the Hibernate Annotations reference documentation, it notes that @OrderBy currently works only on collections having no association table:
http://docs.jboss.org/ejb3/app-server/HibernateAnnotations/reference/en/html_single/#entity-mapping-association-collections

Emmanuel notes that there is an issue open on this over in the following thread:
http://forum.hibernate.org/viewtopic.php?t=954544&highlight=orderby+association+table

It's good to hear support for this is planned. I did a quick search of the JIRA to find the issue so I can follow it, but was unable to locate it. Can anyone confirm that I have interpreted Emmanuel's remark correctly, and if so, what the issue id for this is?

Thanks,
Jonn


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
has been opened recently on hibernate core

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 27, 2006 6:34 am 
Newbie

Joined: Wed Mar 02, 2005 1:28 pm
Posts: 18
Emmanuel,

We are still having problems with @OrderBy on collections with association tables, even with the latest Hibernate Core 3.2.0CR4 and Hibernate Annotations 3.2.0CR2.

I saw your comment on
http://opensource.atlassian.com/project ... se/ANN-402
and it would be really great if you could point out this particular unit test so we can have a look to see what we are doing differently.

Best regards
Mike Wilson


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 11:36 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Apparently it was missing.
I've just commited one
...manytomany.ManyToManyTest.testAssociationTableAndOrderBy()

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 6:40 am 
Newbie

Joined: Wed Mar 02, 2005 1:28 pm
Posts: 18
Thanks Emmanuel,
We'll have a look at it and I'll let you know if we find any peculiarities.
Best regards
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 9:24 am 
Newbie

Joined: Wed Mar 02, 2005 1:28 pm
Posts: 18
Hi again Emmanuel,

We found out why it was not working for us, and I would like to check with you if this is correct behaviour.

We are using Set for our mapped collections, and not Collection like in your unit test. We can see that the items are inserted in the Set according to the order governed by @OrderBy, but apparently Hibernate is not using an order-preserving Set like f ex LinkedHashSet.

We were under the impression that Hibernate would support ordered Sets by using a suitable (ordered) Set subclass when an @OrderBy is specified. Is this assumption wrong?

Best regards
Mike Wilson


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 10:16 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The assumption is correct, there is probably a bug. Open a new isse with a minimal test case.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 03, 2006 4:33 am 
Newbie

Joined: Wed Mar 02, 2005 1:28 pm
Posts: 18
Hi again,

Here is a failing test case; I made some changes to your testAssociationTableAndOrderBy() test case:

Group.java:
- changed "permissions" from Collection to Set

ManyToManyTest.java:
- changed local "permission" vars from Collection to Set
- added an extra permission + check order of all three perms to avoid the 50% chance of random order being correct

Code:
   public void testAssociationTableAndOrderBy() throws Exception {
      Session s = openSession();
      s.enableFilter( "Groupfilter" );
      Permission readAccess = new Permission();
      readAccess.setPermission( "read" );
      readAccess.setExpirationDate( new Date() );
      Permission writeAccess = new Permission();
      writeAccess.setPermission( "write" );
      writeAccess.setExpirationDate( new Date( new Date().getTime() - 10*60*1000 ) );
      Permission executeAccess = new Permission();
      executeAccess.setPermission( "execute" );
      executeAccess.setExpirationDate( new Date( new Date().getTime() - 5*60*1000 ) );
      Set<Permission> coll = new HashSet<Permission>( 2 );
      coll.add( readAccess );
      coll.add( writeAccess );
      coll.add( executeAccess );
      Group group = new Group();
      group.setId( new Integer( 1 ) );
      group.setPermissions( coll );
      s.getTransaction().begin();
      s.persist( group );
      s.flush();
      s.clear();
      group = (Group) s.get( Group.class, group.getId() );
      s.createQuery( "select g from Group g join fetch g.permissions").list();
      Iterator<Permission> permIter = group.getPermissions().iterator();
      assertEquals( "write", permIter.next().getPermission() );
      assertEquals( "execute", permIter.next().getPermission() );
      assertEquals( "read", permIter.next().getPermission() );
      s.getTransaction().rollback();
      s.close();
   }


At the moment I cannot create an account at JIRA (because of mail regulations at work). I can enter an issue later (from home) if you want. Should I add this test case to the existing (closed) bug report?

Best regards
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 4:58 am 
Newbie

Joined: Wed Mar 02, 2005 1:28 pm
Posts: 18
I have now created a new issue in JIRA:
http://opensource.atlassian.com/project ... se/ANN-448

(And while doing it I realized that there is no need for mail confirmation when registering on the Jira site, so sorry about the noise before.)

Best regards
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 22, 2007 10:50 am 
Newbie

Joined: Thu May 24, 2007 11:08 am
Posts: 1
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?

_________________
Simon Ruel
Bell Canada


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.