-->
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.  [ 6 posts ] 
Author Message
 Post subject: Searching for advice using Hibernate
PostPosted: Sun Dec 11, 2005 8:20 am 
Newbie

Joined: Sun Nov 20, 2005 8:08 pm
Posts: 10
I have the follow scenario:

I have a user, this user can belogs to one or more systems and can have one profile in each system.

My database tables are:

    user
    profile
    system
    detail

and my entities are:

    User
    Profile
    System
    Detail


The Detail entity holds reference to 3 others entities: User, Profile and System and i have a Detail set in Usuario entity (eg. Usuario.setDetails).
Right now i don't know if this is the correct way to do the things, i'm almost going to solve this problem in SQL, but i'm asking for some advice here before do it in SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 11:33 am 
Beginner
Beginner

Joined: Fri Jul 22, 2005 3:35 pm
Posts: 24
Location: Buenos Aires, Argentina
Why don't you drop "Detail" from this and view the Profile entity as a many-to-many relationship with User and System. The you can map User with Profile with a Hibernate's one-to-many, and a Profile with a system with a many-to-one. I think you could then put a natural-id around the definitions in "profile" so that Hibernate puts a unique constraint and forces to have only one Profile for each User-System pair.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 12:15 pm 
Newbie

Joined: Sun Nov 20, 2005 8:08 pm
Posts: 10
niqueco wrote:
Why don't you drop "Detail" from this and view the Profile entity as a many-to-many relationship with User and System. The you can map User with Profile with a Hibernate's one-to-many, and a Profile with a system with a many-to-one. I think you could then put a natural-id around the definitions in "profile" so that Hibernate puts a unique constraint and forces to have only one Profile for each User-System pair.


With your sugestion i can do something like this:

User 1 -> System 1-> Profile 1
and
User 1 -> System 2-> Profile 1 ?

Note the same profile can be shared with diferent systems.
This code belongs to a webapp that controls the users in a Single Signon System. Once the user is logged he has diferent profiles in each system under Single Signon.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 2:01 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 3:35 pm
Posts: 24
Location: Buenos Aires, Argentina
rpa_rio wrote:
Note the same profile can be shared with diferent systems.


Then it could be like this:

User ---one-------many---> Profile <---many-------many---> System

See Hibernate reference docs to check how to define a many to many relationship (which will involve a profile_system table).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 2:55 pm 
Newbie

Joined: Sun Nov 20, 2005 8:08 pm
Posts: 10
Then when i add a new User i'll do this:

Profile profile = new Profile();
profile.setSystem(systemInstance);
//profile is an ArrayList used in a JSF component
profiles.add(profile);
User user = new User();
//user.setProfiles(Set profiles) is my setter of profiles Set
user.setProfiles(new HashSet(profiles));
session.save(user);

right?

How is the tables structure in this sugestion?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 7:21 am 
Newbie

Joined: Sun Nov 20, 2005 8:08 pm
Posts: 10
niqueco wrote:
Then it could be like this:

User ---one-------many---> Profile <---many-------many---> System

See Hibernate reference docs to check how to define a many to many relationship (which will involve a profile_system table).


Who will store the UserId? The profile_system table? I mean i need retrieve a list of Profiles from User entity how this can be done without a UserId in profile_system table, if i put the UserId in profile table the profile will not shared with other systems.


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