-->
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: Indexing a Map
PostPosted: Thu Sep 11, 2008 3:23 pm 
Newbie

Joined: Thu Sep 11, 2008 2:55 pm
Posts: 6
Hi,

I got a few problems indexing a somewhat complex usage of a map. I've got two classes in general constructed like this:

Code:
@Entity
@Table(name = "Users")
public class User {

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long userId;

   @MapKey(columns = { @Column(name = "UserProfileEntryKey") })
   @OneToMany(fetch = LAZY, cascade = CascadeType.ALL)
   @Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
   private Map<String, UserProfileEntry> profile;

   // getter and setters and so on
}

@Entity
public class UserProfileEntry {

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long id;

   @Enumerated(value = EnumType.ORDINAL)
   @Basic(optional = false)
   private PrivacyLevel level;

   @ManyToOne(optional = false)
   @IndexedEmbedded(depth = 1)
   private User user;

   @Basic(optional=false)
   private String value;

   // getters and setters....

}


So, you can see that I'm constructing a user profile. There are two requirements in our system that dictate this structure with the UserProfileEntries: 1. The profile should be changeable at runtime by adding or deleting fields and 2. the access restrictions (called PrivacyLevel) for each field shall be changeable by the user.

I need to construct a search on the user profiles that uses the UserProfileEntry.values for searching but has to respect the privacy level of each UserProfileEntry and that has to return User instances. Is there a preferred way to achieve this? I've tried several approaches including a custom field bridge that writes all user fields ordered by privacy level inside the User index but none of them did a correct index update on UserProfileEntry changes.

Thanks for the help
Johannes


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 3:55 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
you need
Code:
@ManyToOne(optional = false)
@ContainedIn
private User user;

instead of IndexedEmbedded,
and put
Code:
@...
@IndexedEmbedded
private Map<String, UserProfileEntry> profile;


and your root entity is missing @Indexed

Code:
@Entity
@Indexed
@Table(name = "Users")
public class User {

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 4:23 am 
Newbie

Joined: Thu Sep 11, 2008 2:55 pm
Posts: 6
Thanks for the answer.

s.grinovero wrote:
you need
Code:
@ManyToOne(optional = false)
@ContainedIn
private User user;

instead of IndexedEmbedded


Oh, I see, that IndexEmbedded there was an artefact from something else I tried.

s.grinovero wrote:
and put
Code:
@...
@IndexedEmbedded
private Map<String, UserProfileEntry> profile;


and your root entity is missing @Indexed

Code:
@Entity
@Indexed
@Table(name = "Users")
public class User {


Ok, I've tried this mapping, but I don't know how to build a query that respects the privacy level of each UserProfileEntry. If I look at the index with luke than each Document for the User contains all UserProfileEntry values and all privacy levels concatenated in one field (profile.level and profile.value), so I can't decide which privacy level belongs to which value.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.