-->
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.  [ 3 posts ] 
Author Message
 Post subject: ManyToMany Mapping with custom where clause
PostPosted: Wed Feb 20, 2008 5:53 am 
Newbie

Joined: Wed Feb 20, 2008 5:49 am
Posts: 2
Hi everyone,

I'm encountering a little problem with annotations. I was able to have ManyToMany collections with a generated query using the where attribute on the set tag (with xml definitions)


Code:
<class table="TABLEA" ....>

<set name="affaires" table="LINKS"  inverse="true" where="LINK_TYPE='EVT' and FROM_TYPE='EVT' and TO_TYPE='AFF'">   
   <key column="FROM_ID" />
        <many-to-many column="TO_ID" class="com.itnsa.gestion.bean.FAffaires"/>
</set>
...
</class>


which generated the corresponding join query clause

Code:
... WHERE TABLEA.ID = LINKS.FROM_ID
AND    LINKS.LINK_TYPE='EVT'
and    LINKS.FROM_TYPE='EVT'
and    LINKS.TO_TYPE='AFF'
AND    TABLEB.ID = LINKS.TO_ID ...



Now using annotations, one of the closest try i used is something like this

Code:
   @ManyToMany(
         fetch = FetchType.LAZY
   )
   @JoinTable(
         name="LINKS",
         joinColumns= {@JoinColumn(name="FROM_ID")},
         inverseJoinColumns= {@JoinColumn(name="TO_ID")}
   )
   @Where(clause="LIP_TYPE_LIEN='EVT' and LIP_TYPE_PIECE_1='EVT' and LIP_TYPE_PIECE_2='AFF'")


which generated :

Code:
... TABLEA.ID = LINKS.FROM_ID
AND    TABLEB.LINK_TYPE='EVT'
and    TABLEB.FROM_TYPE='EVT'
and    TABLEB.TO_TYPE='AFF'
AND    TABLEB.ID = LINKS.TO_ID ...



the @Where is working as intended, but it's not what i was looking for.

I've searched through the documentation, the forum, googled it but i couldn't found any clue on how to do this.
Is there a corresponding attribute or annotation to the where attribute of the set tag ? Is it even possible with annotations ?

Thanks,

Sebastien.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 1:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I think you want
Code:
@WhereJoinTable

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 5:43 am 
Newbie

Joined: Wed Feb 20, 2008 5:49 am
Posts: 2
That's it ! Thank you very much. I'm feeling dumb right now, i've missed the thing : ยง2.4.6.1 in the reference guide.

Thanks again


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