I am a beginner using hibernate. I have a userProfiles table and I want to create another table userTrack which has 2 userProfilesIds only. This table sets persmissions.
This is my user profile java class.
public class UserProfileObject implements Serializable{ //private static final long serialVersionUID = 1L; private Set<UserTrackObject> userTracks = new HashSet<UserTrackObject>(0); private int UserProfileObjectId; // rest of attributes public int getUserProfileObjectId() { return UserProfileObjectId; } public void setUserProfileObjectId(int userProfileObjectId) { UserProfileObjectId = userProfileObjectId; } public Set<UserTrackObject> getUserTracks() { return userTracks; } public void setUserTracks(Set<UserTrackObject> userTracks) { this.userTracks = userTracks; } //rest of getters and setters }
This is my UserTrack Class. The purpose of this table is to see if user 1 has permission to see user 2 details. Permission does not go both ways. for example one user x can see user y info but not the opposite.
public class UserTrackObject implements Serializable { private UserProfileObject userProfileObject; private UserProfileObject userProfileObject1; public UserProfileObject getUserProfileObject() { return userProfileObject; } public void setUserProfileObject0(UserProfileObject userProfileObject) { this.userProfileObject = userProfileObject; } public UserProfileObject getUserProfileObject1() { return userProfileObject1; } public void setUserProfileObject1(UserProfileObject userProfileObject1) { this.userProfileObject1 = userProfileObject1; } }
This is my xml mapping file.
<class name="objects.UserProfileObject" table="userProfiles"> <id name="UserProfileObjectId" column="UserProfileObjectId"> <generator class="native" /> </id> <set name="userTracks" cascade="all" > <key> <column name="UserProfileObjectId" /> </key> <many-to-many class="objects.UserTrackObject" /> </set> <!-- rest of properties --> </class> <class name="objects.UserTrackObject" table="userTrack"> <composite-id> <key-many-to-one name="userProfileObject" class="objects.UserProfileObject" > <column name="UserProfileObjectId"/> </key-many-to-one> <key-many-to-one name="userProfileObject1" class="objects.UserProfileObject"> <column name="UserProfileObjectId"/> </key-many-to-one> </composite-id> </class>
No comments:
Post a Comment