[jboss-user] [EJB 3.0] - Exception from Hibernate when I alter relation relationship

webmarck do-not-reply at jboss.com
Mon Sep 18 07:50:48 EDT 2006


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;
  | }
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3972278#3972278

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3972278



More information about the jboss-user mailing list