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.  [ 2 posts ] 
Author Message
 Post subject: Filter on a manytoone association
PostPosted: Mon Apr 19, 2010 5:36 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

I'm trying to filter Offers based on the property Region from a manytoone association with City.

I understand I have to place the filter on Offer and that I can use arbitrary sql in the condition but I don't understand how I would phrase the sql.

Initially I thought placing the filter on City would do the trick, but there seems to be no "magical" detection of filters on associations like these.

I have the following classes
Code:
@Entity
@Filter(name="region", condition="[???]")
@FilterDef(name="region", parameters=@ParamDef(name="regionId",type="java.lang.Long"))
Offer

   @Embedded
   Address address;
   
@Embeddable
Address
   
   @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
   @JoinColumn(name = "FK_CityID")
   City city;

@Entity   
City

   @ManyToOne(optional=true,cascade=CascadeType.MERGE,fetch=FetchType.LAZY)
   @JoinColumn(name="FK_regionID", nullable=true)
   Region region;

@Entity   
Region
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name="regionId", nullable=false, insertable=false, updatable=false)
   public Long getId() {
      return id;
   }


Any ideas on how to solve this? Is is at all possible using filters?

Kind regards,

Marc


Top
 Profile  
 
 Post subject: Re: Filter on a manytoone association
PostPosted: Mon Apr 19, 2010 8:29 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
What do you want to filter? The file you posted is very incomplete and I can't make out which manytoone you want to filter. In general you can't filter ToOne associations though, because "it changes the cardinality from *ToOne to *ToOneOrZero". I don't understand the reasoning but you can either patch hibernate or get the filtered associated entity with a filter on the entity itself instead of the association.


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