-->
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: Associationoverride, mapping includePaths
PostPosted: Fri Jun 15, 2012 11:48 am 
Pro
Pro

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

How are you supposed to map an includePaths relation to an object that has a combined primary key?

Code:
@Entity
@AssociationOverrides({
   @AssociationOverride(name = "pk.user",
      joinColumns = @JoinColumn(name = "FK_userId")),
   @AssociationOverride(name = "pk.group",
      joinColumns = @JoinColumn(name = "FK_groupId"))
})
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.GROUP)
public class GroupMember{

   @EmbeddedId
   public GroupMemberId getPk() {
      return pk;
   }
}   

@Embeddable
public class GroupMemberId implements Serializable{
   
   public GroupMemberId(){}
   
   public GroupMemberId(Usor user, Group wallGroup){
      this.user=user;
      this.group = wallGroup;
   }

   @ManyToOne(optional=false)
   @ContainedIn
   public User getUser() {
      return user;
   }

   public void setUser(User user) {
      this.user = user;
   }

   @ManyToOne(optional=false)
   public Group getGroup() {
      return group;
   }
}

@Entity
@Indexed
public class User{

   @OneToMany(cascade=CascadeType.ALL,orphanRemoval=false,fetch=FetchType.LAZY, mappedBy="pk.user")
   @IndexedEmbedded(prefix="member.",includePaths={"pk.group.id","blocked","active"})
   public List<GroupMember> getGroupMemberships() {
      return groupMemberships;
   }
}


I would expect that Hibernate Search would accept "pk.group.id" as a path on getGroupMemberships. But it doesn't.
I also tried adding @EmbeddedId to getPk().

My workaround so far was adding a @Transient @IndexedEmbedded getGroup() member to GroupMember, but apart from it being somewhat ugly, I also run into Lazy Exception errors in some situations on IndexedEmbedded relations within the Group.

Is there a definitive answer on how to map Embedded Primary keys when used with Hibernate Search?


Top
 Profile  
 
 Post subject: Re: Associationoverride, mapping includePaths
PostPosted: Fri Jun 15, 2012 12:49 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
A related issue that I don't get with this is:

Code:
public void removeMember(GroupMember member){

   member = (GroupMember) get(GroupMember.class,member.getPk());
      
   Group group = member.getGroup();
   group.getMembers().remove(member);


results in a lazy init exception on group.getMembers


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.