• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB 3.0 HibernateException on EntityManager.remove(object) function

 
Scafuro Te
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have a problem on my ejb application...

On runing the project, everytime i try to do a delete of a specifical record, i have this exception:

javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [ejb.Profili#26428513]


I found that the problem is dued to this part of code:

HttpSession session = request.getSession(true);
try{
ProfiliFacadeLocal profiliFacade = (ProfiliFacadeLocal) lookupProfiliFacade();
List profili = profiliFacade.findAll();
String key =(String)session.getAttribute("idProf");
try{

for (Iterator itProf = profili.iterator(); itProf.hasNext(); ) {
Profili elem = (Profili) itProf.next();
if(elem.getIdprof().equals(request.getParameter("idProf"))){
out.println("<h2>Rimozione esame : " +elem.getIdcorso()+ " riuscita</h2");
profiliFacade.destroy(elem);

}
}


where the profiliFacade.destroy(profili) function is so defined:

public void destroy(Profili profili) {
em.merge(profili);
em.remove(profili);
}
//with em as "EntityManager em"


All the entitymanager operation like merge, create and so one give me no problem, it works, i have the problem only with the
EntityManager.remove(object)
function:
does someone know where is the bug and what i have to do?
tkx
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the entire exception stacktrace? Also, the code in the findAll() method. There was a similar discussion about this here .
 
Scafuro Te
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
of course!

javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [ejb.Profili#26428511]
org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181)
org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
$Proxy274.destroy(Unknown Source)
web.Destroy.processRequest(Destroy.java:61)
web.Destroy.doGet(Destroy.java:85)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)



and here is the code:

public List findAll() {
return em.createQuery("select object(o) from Profili as o").getResultList();
}
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not duplicate post. The appropriate forum for EJB 3 JPA questions is the ORM forum.

I am going to close this thread and let the one in ORM remain for answers.

Thanks

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic