-->
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.  [ 1 post ] 
Author Message
 Post subject: Interesting Architectural / Hibernate Dillemma
PostPosted: Tue Feb 20, 2007 9:12 pm 
Newbie

Joined: Sun Dec 17, 2006 3:14 pm
Posts: 3
Proving that I am capable of overanalyzing myself into oblivion, I came up with the following (code abbreviated for brevity.. *lol*)

Code:
public class User
{
  private Integer userId;
  private Set<Role> roles = new HashSet<Role>();
  ...
  ...
  public void addRole( Role role ) { roles.add( role ); }
  public Role getRole( Class roleClass ) { ...; }
}

public class Role<T>
{
  private T member;

  public Role( T memberRole ) { member = memberRole; }
  public T get() { return member; }
  public boolean supportsRole( String roleName ) { ... }
  public void addTo( User user ) { ... }
  etc.
}

public class SampleRole1
{
  private String someUniqueAttribute;
  ...
  ...
}



Under this "assignment of roles" philosophy, I might have a User who is a SampleRole1, a SampleRole2, etc. Each "role" is actually a wrapper for a regular POJO containing whatever role-specific data is needed.

For example:

Code:
SampleRole1 role1 = new SampleRole1();
SampleRole2 role2 = new SampleRole2();
User user = new User();
user.addRole( new Role<SampleRole1>( role1 ));
user.addRole( new Role<SampleRole2>( role2 ));


Later in code, I can a method in User to obtain the details of SampleRole2 by saying (method described is not shown in code, but you get the idea)

Code:
SampleRole2 role = user.getRole(SampleRole2.class);


But now I'm a bit stuck. How would I go about mapping this in Hibernate? I *think* in addition to the users table, I want to have a table for each role with a userId column. Ideally, I'd like to be able to add new roles without impacting anything other than the roles themselves.... but... I'm confused how I would map this since the types aren't known until runtime. How would Hibernate know which table to load from and save to?

If confusion were valuable, I'd be rich.

Dan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.