0 Replies Latest reply on Sep 18, 2006 7:50 AM by webmarck

    Exception from Hibernate when I alter relation relationship

    webmarck

      I have been fighting with a error that I just can't see why happens - so now I ask you smart people.

      I have a entitybean with a one to one connection to another entity bean.


      When I try to change the username like this:

      Subscriber sub = (Subscriber) em.createQuery("...").getSingleResult();
       sub.setUserName("newusername"); //notice that setUserName actually is getRoles().setUserName("newusername");
       sub.setPassword("newpassword");
       sub.getRoles().setRoles("newRole");
       //autocommit
      

      I get the following exception:

      13:01:46,730 INFO [MpSupport-web] signupStep1 error, java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=nicolai/87, BranchQual=, localId=87] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.PersistenceException: org.hibernate.HibernateException: identifier of an instance of dk.niro.mpsuite.persist.SubscriberRoles was altered from oldusername to newusername)

      But why??

      @Entity
      public class Subscriber implements Serializable{
      ...
      @OneToOne(cascade={CascadeType.ALL}, optional=false)
      @JoinColumn(name="username", unique=true)
      public SubscriberRoles getRoles() {
       return roles;
      }
      
      public void setRoles(SubscriberRoles roles) {
       this.roles = roles;
      }
      
      public void setUserName(String username) {
       getRoles().setUserName(username);
      }
      
      @Transient
      public String getUserName(){
       return getRoles().getUserName();
      }
      }
      
      @Entity
      public class SubscriberRoles implements Serializable{
      
      private String userName;
      
      private String roles;
      
      public SubscriberRoles(){}
      
      public SubscriberRoles(String username, String roles){
       userName = username;
       this.roles = roles;
      }
      public String getRoles() {
       return roles;
      }
      
      public void setRoles(String roles) {
       this.roles = roles;
      }
      
      @Id
      public String getUserName() {
       return userName;
      }
      
      public void setUserName(String userName) {
       this.userName = userName;
      }
      }