-->
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: Filtering on Many to Many relationship
PostPosted: Wed Apr 19, 2006 6:11 am 
Newbie

Joined: Wed Apr 19, 2006 5:51 am
Posts: 2
Location: UK
I am using EJB 3.0 persistence shipped with JBoss AS 4.0.4.CR2 (EJB 3.0 RC 6).

I have a Many to Many relationship between two entities. I need to filter the collection from both entities based on dates within the entities.

E.g. Within a class 'C' I have a Collection of 'CtoD' entities defined in a Many to Many relationship that I want to filter by the dates on 'CtoD'.

Code:
   
@ManyToMany(mappedBy = "owners",  cascade=CascadeType.ALL, fetch= FetchType.EAGER)
@Filter(name = "timeFilter", condition = ":time between dateEffective and dateInactive")
private Collection<CtoD> cdCollection = new ArrayList<CtoD>();


(I am using field access in the above example).
In this example the class CtoD has columns called dateEffective and dateInactive.

When I activate the 'timeFilter' and set the ':time' parameter and then try and fetch a 'C' I get the following error:

Code:
10:03:20,759 WARN  [JDBCExceptionReporter] SQL Error: 1054, SQLState: 42S22
10:03:20,759 ERROR [JDBCExceptionReporter] Unknown column 'cdcollecti1_.dateEffective' in 'on clause'
10:03:20,759 INFO  [DefaultLoadEventListener] Error performing load command
org.hibernate.exception.SQLGrammarException: could not load an entity: [com.tecssphere.chj.C#1]
....


I can only filter a many to many relationship using columns within the joining table which is not what I require.

Can anyone help with this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 3:25 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Maybe write 2 OneToMany relations on a middle object.

C - has One2Many to M

M (middle) - has Many2One to C and Many2One to D

D - has One2Many to M

And define filter on the M.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 9:37 am 
Newbie

Joined: Wed Apr 19, 2006 5:51 am
Posts: 2
Location: UK
I thought of that but it means compromising my design to enable this feature! There really is no information on the relationship itself so I would rather not have to introduce this as it over complicates and already complex situation.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 9:36 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
this is intrusive but you can use a
session.createFilter(c.cdCollection(), "this.begindDate = :begindate ...")

_________________
Emmanuel


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.