-->
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.  [ 7 posts ] 
Author Message
 Post subject: Entity Association Help
PostPosted: Tue Aug 05, 2008 3:00 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
I'm having a hard time wrapping my head around this.

I have a user entity and an event entity.
Currently i have a bunch of lists for users who are part of an event.

I'm trying to figure out the easiest way of doing the following.
I need some users to be special in that for a certain event each of the users in that set can have a set of users pertaining to that event.

From a db perspective this table will represent a "list" and it look something like the following.

event id | superuser id | regularuser id
---------------------------------------------
_1_____|_1_________|_2__________
_1_____|_1_________|_3__________
_1_____|_2_________|_6__________
_1_____|_2_________|_7__________
_1_____|_2_________|_8__________
_2_____|_1_________|_3__________
_2_____|_2_________|_4__________
_2_____|_3_________|_5__________

For each EVENT there can be many special users and a regular user cannot be duplicated.

I'm thinking the only way to put a set of users within a set of users per event is to create another entity for the superusers. This just seems redundant if the superusers will only have 1 or 2 more attributes than the regular users.

Any suggestions are welcome!
Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 4:30 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
anyone have any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 5:55 pm 
Newbie

Joined: Wed Aug 13, 2008 2:13 am
Posts: 3
Why not just create a join table with an extra column IS_SUPER? You won't need an extra entity in your java for this, from what I understand.

For instance

TABLE_USER_EVENT
================
fk_event_id
fk_user_id
is_super

You then set is_super for each event by user that has special privs.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 8:37 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
RJW.. you got the right idea but your missing the biggest point.
My question isn't really how to seperate an super user with a regular user, its how can i have a set of users for these for a user for an event.

maybe if i describe it in a non technical way.

each event can have 1 or more super users. each of these super users will have a list of invitations, a list of attendance, and so on. These lists are full of user entities.e

what i currently have is an event has these user lists, but i need to move them away from the event entity and move them to this super user entity, but also make it so that these lists are unqiue for each event.

hope thats understandable! Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 17, 2008 4:02 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
I'm still stuck on this.. can anyone help?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 18, 2008 9:29 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
So i think i have logically figured this out, but i need assitance technically.

Logically I created another entity called AttendanceListEnt. This entity will house the user that owns this list, the event it relates to and the lsit of users.
Code:
private UserEnt user;
private EventEnt event;
   
private Set<UserEnt> userList = new HashSet<UserEnt>();

@ManyToOne
@JoinColumn
@NotNull
public UserEnt getUser() {
   return user;
}

@Column(nullable=true)
public EventEnt getEvent() {
   return event;
}

@Column(nullable=true)
public Set<UserEnt> getUserList() {
   return userList;
}


In my UserEnt I added.
Code:
private Set<AttendanceListEnt> promoterInviteList = new HashSet<AttendanceListEnt>();
private Set<AttendanceListEnt> promoterAttendedList = new HashSet<AttendanceListEnt>();
private Set<AttendanceListEnt> promoterAttendingList = new HashSet<AttendanceListEnt>();
private Set<AttendanceListEnt> promoterNotAttendingList = new HashSet<AttendanceListEnt>();

@OneToMany (cascade = {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy = "user", fetch=FetchType.EAGER)
@org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.SAVE_UPDATE)
public Set<AttendanceListEnt> getPromoterInviteList() {
   return promoterInviteList;
}

@OneToMany (cascade = {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy = "user", fetch=FetchType.EAGER)
@org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.SAVE_UPDATE)
public Set<AttendanceListEnt> getPromoterAttendedList() {
   return promoterAttendedList;
}

...


I have not modified anything in the EventEnt.
Now i get this error when running.
org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: AttendanceListEnt, for columns: [org.hibernate.mapping.Column(userList)]

I think the whole set inside a set has confused me so if anyone can help me out i would highly appreciate it!

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 18, 2008 10:28 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
Well i found a fix to that error.
In the AttendanceList entity I now have.

Code:
@ManyToOne
@JoinColumn(name = "user_id")
@NotNull
public UserEnt getUser() {
   return user;
}

@OneToOne
@JoinColumn(name = "event_id")
@NotNull
public EventEnt getEvent() {
   return event;
}

@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER, targetEntity=UserEnt.class)
public Set<UserEnt> getUserList() {
   return userList;
}


This resulted in 2 tables
attendancelist_userent
-AttendanceListEnt_id
-userList_id

and

attendancelist
-id
-event_id
-user_id

Unfortunately i was extecting more tables! Tables to cover the ...
Code:
private Set<AttendanceListEnt> promoterInviteList = new HashSet<AttendanceListEnt>();
private Set<AttendanceListEnt> promoterAttendedList = new HashSet<AttendanceListEnt>();
private Set<AttendanceListEnt> promoterAttendingList = new HashSet<AttendanceListEnt>();
private Set<AttendanceListEnt> promoterNotAttendingList = new HashSet<AttendanceListEnt>();

... sets.
Am i right in thinking this would give me more? How can i accomplish this?


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