-->
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.  [ 4 posts ] 
Author Message
 Post subject: Adding support for key-many-to-one in Criteria queries
PostPosted: Mon Jun 13, 2005 6:27 pm 
Beginner
Beginner

Joined: Mon Jun 13, 2005 5:52 pm
Posts: 43
Hello,

Are there plans to add key-many-to-one capabilities to the Criteria API? I found a post related to this from Feb 2004:

http://forum.hibernate.org/viewtopic.php?t=927914

I have a relationship that looks similar to:

Code:
Person --< Membership >-- Group

The Membership object contains person and group properties.

I realize that composite keys are not the preferred identifier type, but they have worked well in our application so far using Hibernate. Other than this minor issue, the Criteria API works fantastic--especially for "advanced search" features.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 8:13 pm 
Beginner
Beginner

Joined: Mon Jun 13, 2005 5:52 pm
Posts: 43
Okay... this works. I created a "dummy" property that has no getters/setters:

Code:
  private Person internalWorkaroundPerson;


I then created a read-only mapping:

Code:
<many-to-one name="internalWorkaroundPerson" class="Person" column="person_id" insert="false" update="false" access="field" />


And now the alias works:

Code:
    final Criteria memberCriteria = session.createCriteria(Membership.class);
    memberCriteria.createAlias("internalWorkaroundPerson", "prsn");


It's hack-ish, but it looks like it will work.

If anyone has alternatives, I'm open to suggestions.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 11:01 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Nope, that's the work around for now until the actual code is changed. I can't see it very high on the priority list.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 11:47 am 
Beginner
Beginner

Joined: Mon Jun 13, 2005 5:52 pm
Posts: 43
Would it be simple to add some sort of error prevention code that restricts the API user from creating an alias or subquery to in a key-many-to-one relationship? There's no graceful handling of the API misuse--Hibernate just writes incorrect SQL and it is up to the API user to search through the forums to figure out why that happened.

If someone concurs, I'll add a change request to JIRA.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.