-->
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: Merging Entities in Web Application
PostPosted: Fri Nov 20, 2009 11:10 pm 
Beginner
Beginner

Joined: Fri Nov 13, 2009 4:05 pm
Posts: 30
The following entities are defined in my system:

Code:
@Entity
@Table(name="roles")
public class Role
{
   @Id
   @GeneratedValue
   @Column(name="ROLE_ID")
   private Long id;
   @OneToMany(
         fetch=FetchType.LAZY,
         cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},
         mappedBy="role"
   )
   private List<RoleFunctionAccess> roleFunctionAccess;
        // other stuff
};   

@Entity
@Table(name="role_function_access")
public class RoleFunctionAccess
{
   @SuppressWarnings("serial")
   @Embeddable
   public static class Id implements Serializable
   {
      // Composite Id Variables
      @Column(name = "ROLE_ID")
      private Long roleId;
      
      @Column(name = "FUNCTION_ID")
      private Long functionId;
                // other stuff
         }   
   // Variables
   @EmbeddedId
   private Id id = new Id();
   
   @Column(name = "ACCESS_FLAGS")
   private Long accessFlags;
   
   @ManyToOne
   @JoinColumn(name="ROLE_ID",insertable=false,updatable=false)
   private Role role;
   // other stuff
};


When I edit a role, I do rolesService.findById() to get the unique Role entity from the datastore and I pass this to my page for rendering. The problem I face first of all is that I need to place some constraints of the RoleFunctionAccess entity in that if the accessFlags gets set to 0 the record should be deleted, not updated. Additionally, if the value is NULL, it should not be inserted into the database.

These types of constraints, do I have to handle this on my own or is there a way to do this within Hibernate?


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.