[jboss-user] [EJB 3.0] - Re: javax.persistence.EntityNotFoundException: deleted entit

misterpea do-not-reply at jboss.com
Tue Dec 16 03:29:29 EST 2008


My colleague found a solution, but first of all an amendment ...

In my company bean I had:


  | 	@OneToMany(cascade = CascadeType.ALL,
  | 			   mappedBy = "company",
  | 			   fetch = FetchType.EAGER)
  | 	private Set<Employee> employees;
  | 

not


  | 	@OneToMany(cascade = CascadeType.ALL,
  | 			   mappedBy = "employee",
  | 			   fetch = FetchType.EAGER)
  | 	private Set<Employee> employees; 
  | 

but anyway that wasn't problem.
This is what we did to fix the error we were getting ...

In the Company bean, changed employees to:


  | 	@OneToMany(cascade = {CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH}, 
  | 			   mappedBy = "company",
  | 			   fetch = FetchType.EAGER)
  | 	private Set<Employee> employees;
  | 

So pretty much just removing the CascadeType.PERSIST (which is contained within CascadeType.ALL).

This works but don't understand why, if someone can explain that'd be awesome.

(To save myself here ... I did try this at some point but it musn't have worked before due to other code "fixes" I was trying out to fix this problem!)

There is one little problem to this solution though, if it is a problem to some at all.

If you have a new Company object containing a set of new Employees, those employees won't get persisted. You won't get an error message or warning message. It just doesn't get persisted.

Hmm ...

Hope this helps someone.

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

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



More information about the jboss-user mailing list