[jboss-user] [JBoss Seam] - org.hibernate.exception.DataException: could not initialize

ernest210 do-not-reply at jboss.com
Tue Jan 23 16:18:45 EST 2007


My problem.
I have two class Client and Book with relations OneToMany set on cascade "REMOVE".
Now I must change scope "SESSION" on "CONVERSATION". 
Now (after the change) when i execute delete method on Client i have error. When scope is set on SESSION everything is ok but when is set on CONVERSATION then I have error. Why? PLEASE HELP! 
How it looks:

Client CLASS

  | package pl.test.client;
  | 
  | import java.io.Serializable;
  | import java.util.HashSet;
  | import java.util.Set;
  | 
  | import javax.persistence.CascadeType;
  | import javax.persistence.Entity;
  | import javax.persistence.GeneratedValue;
  | import javax.persistence.Id;
  | import javax.persistence.OneToMany;
  | import javax.persistence.Table;
  | 
  | import org.jboss.seam.annotations.Name;
  | 
  | @Entity
  | @Name("client")
  | @Table(name="clients")
  | public class Client implements Serializable {
  | 	
  | 	 /**
  | 	 * 
  | 	 */
  | 	private static final long serialVersionUID = -3074021688217036261L;
  | 	
  | 	private int id;		
  | 	private String name;
  | 	private Set<Investment> books = new HashSet<Investment>();  
  | 		 
  | 	@Id @GeneratedValue
  | 	public int getId() {
  | 		return id;
  | 	}
  | 	public void setId(int id) {
  | 		this.id = id;
  | 	}	
  | 	@OneToMany(cascade=CascadeType.REMOVE, mappedBy="client")	
  | 	public Set<Investment> getBooks() {
  | 		return books;
  | 	}
  | 	public void setBooks(Set<Investment> books) {
  | 		this.books = books;
  | 	}
  | 	public String getName() {
  | 		return name;
  | 	}
  | 	public void setName(String name) {
  | 		this.name = name;
  | 	}	
  | }
  | 

Book CLASS

  | package pl.test.client;
  | 
  | import java.io.Serializable;
  | 
  | import javax.persistence.Entity;
  | import javax.persistence.GeneratedValue;
  | import javax.persistence.Id;
  | import javax.persistence.JoinColumn;
  | import javax.persistence.Table;
  | 
  | import org.jboss.seam.annotations.Name;
  | 
  | @Entity
  | @Name("book")
  | @Table(name="books")
  | public class Book implements Serializable{
  | 
  | 	/**
  | 	 * 
  | 	 */
  | 	private static final long serialVersionUID = 1624659788044987338L;
  | 	
  | 	private int id;		
  | 	private String bookname;
  | 	private Client client;
  | 	
  | 	@JoinColumn(name="books")
  | 	public String getBookname() {
  | 		return bookname;
  | 	}
  | 	public void setBookname(String bookname) {
  | 		this.bookname = bookname;
  | 	}
  | 	public Client getClient() {
  | 		return client;
  | 	}
  | 	public void setClient(Client client) {
  | 		this.client = client;
  | 	}
  | 	@Id 
  | 	@GeneratedValue
  | 	public int getId() {
  | 		return id;
  | 	}
  | 	public void setId(int id) {
  | 		this.id = id;
  | 	}
  | }
  | 

And MANAGER who i execute

  | package pl.test.client;
  | 
  | import static javax.persistence.PersistenceContextType.EXTENDED;
  | 
  | import java.io.Serializable;
  | import java.util.List;
  | 
  | import javax.ejb.Remove;
  | import javax.ejb.Stateful;
  | import javax.persistence.EntityManager;
  | import javax.persistence.PersistenceContext;
  | 
  | import org.jboss.seam.annotations.Begin;
  | import org.jboss.seam.annotations.Destroy;
  | import org.jboss.seam.annotations.End;
  | import org.jboss.seam.annotations.Factory;
  | import org.jboss.seam.annotations.In;
  | import org.jboss.seam.annotations.Logger;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Out;
  | import org.jboss.seam.annotations.datamodel.DataModel;
  | import org.jboss.seam.log.Log;
  | 
  | @Stateful
  | @Name("clientManager")
  | public class ClientManagerBean implements Serializable, ClientManager{
  | 
  | 	/**
  | 	 * 
  | 	 */
  | 	private static final long serialVersionUID = 6887290828466517147L;
  | 		 
  | 	@DataModel	
  | 	private List<Client> clientsList;
  | 	
  | 	@In(required = false)
  | 	@Out(required = false)
  | 	private Client client;
  | 	
  | 	@PersistenceContext(type=EXTENDED)
  | 	private EntityManager em;
  | 	
  | 	public void delete() {			
  | 		if (client!=null){	
  | 			client = em.merge(client);
  | 			clientsList.remove(client);
  | 	        em.remove(client);
  | 	        client=null;
  | 	      }
  | 	}	
  | 	@Factory("clientsList")	
  | 	public void findClients() {		
  | 		clientsList = em.createQuery("from Client cli").getResultList();		
  | 	}	
  | 	@Remove 
  | 	@Destroy
  | 	public void destroy() {		
  | 	} 
  | }
  | 

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

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



More information about the jboss-user mailing list