Originally posted by alius
Sanjiv
TestRecord testRec = new TestRecord ();
@Entity public class User { @Id private int id; private String firstName; private String lastName; @OneToMany( mappedBy = "owner" ) protected Set<Profile> profiles = new HashSet<Profile>(); // ... } @Entity public class Profile { @Id private int id; @ManyToOne( optional = false, fetch = LAZY ) private User owner; @OneToOne( optional = false ) Phone phone; private Status status; // ... } @Entity public class Phone { @Id private int id; private String number; // ... } public class RemoteFacadeImpl { public void updateProfile(Profile newProfile) { Profile oldProfile = em.find(Profile.class, newProfile.getId()); // fix some relations newProfile.setUser(oldProfile.getUser()); // do udpate - affects only Profile and Phone related objects newProfile = em.merge(newProfile); } // public void createProfile(Profile newProfile) {} // deleteProfile(int profileId){} // public void createUser(User newUser) {} // public void updateUser(User newUser) {} // public void deleteUser(int userId) {} // + methods to manage the User - Profile relation }
Leave a comment: