*
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3.0 HibernateException on EntityManager.remove(object) function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3.0 HibernateException on EntityManager.remove(object) function" Watch "EJB 3.0 HibernateException on EntityManager.remove(object) function" New topic
Author

EJB 3.0 HibernateException on EntityManager.remove(object) function

Scafuro Te
Greenhorn

Joined: Oct 08, 2007
Posts: 18
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

Joined: Jul 20, 2005
Posts: 9937
    
159

Can you post the entire exception stacktrace? Also, the code in the findAll() method. There was a similar discussion about this here .


[My Blog] [JavaRanch Journal]
Scafuro Te
Greenhorn

Joined: Oct 08, 2007
Posts: 18
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3.0 HibernateException on EntityManager.remove(object) function
 
Similar Threads
EJB 3.0 HibernateException on EntityManager.remove(object) function
Enterbrise bean with nullpointerexception :-(
EJB QL - Changes with data in Table NOT REFLECTED
Rephrase: Does the DOA need to be an session bean as well? SOS.... lossing hairs...
Problem with ROUND function on H2 database