I use Hibernate 3.2.6.GA and i am able to create and update the entity Mailinglist but get the following error if i try to remove it.
Code:
javax.faces.FacesException: javax.ejb.EJBException: nested exception is: c2m2.api.PersistenceException: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at ch.centrisag.c2m2.webui.delegate.AdminDelegate.deleteMaillist(AdminDelegate.java:285)
at ch.centrisag.c2m2.webui.control.notification.MaillistQueryAction.delete(MaillistQueryAction.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.el.parser.AstValue.invoke(Unknown Source)
at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:75)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:54)
at javax.faces.component.UICommand.broadcast(UICommand.java:121)
at org.ajax4jsf.component.UIDataAdaptor.broadcast(UIDataAdaptor.java:1359)
at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:317)
at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:292)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:249)
at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:462)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:103)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:76)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:148)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:154)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:260)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:366)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:493)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3212)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1983)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1890)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1344)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
Caused by: javax.ejb.EJBException: nested exception is: c2m2.api.PersistenceException: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at c2m2.ejb.AdminServicesBean.deleteMaillist(AdminServicesBean.java:496)
at c2m2.ejb.AdminServicesEJB_1iookz_ELOImpl.deleteMaillist(AdminServicesEJB_1iookz_ELOImpl.java:81)
at c2m2.webui.delegate.AdminDelegate.deleteMaillist(AdminDelegate.java:281)
As i found out it seems to have to do with my OnToMany relationship i use on the entity. The entities causing the error are looking as follows:
Code:
@Entity
public class MaillistAssociation extends BaseEntity {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_BO_MAILLIST")
@Column(name="ID")
private Long id;
@ManyToOne
@JoinColumn(name = "MAILLIST_ID")
private Maillist maillist;
.
.
.
}
@Entity
@Table(name="CM_MAILLIST")
@SequenceGenerator(name="SEQ_MAILLIST", sequenceName="SEQ_CM_MAILLIST")
public class Maillist extends BaseEntity {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_MAILLIST")
@Column(name="ID")
private Long id;
@Basic
@Column(name="NAME")
private String name;
@ManyToMany(
fetch=FetchType.EAGER,
cascade={CascadeType.ALL}
)
@JoinTable(
name = "CM_MAILLIST_EMAIL",
joinColumns = {@JoinColumn(name = "MAILLIST_ID")},
inverseJoinColumns = {@JoinColumn(name = "EMAIL_ID")}
)
private Set<Email> emails = new HashSet<Email>();
@OneToMany(mappedBy="maillist")
private Set<MaillistAssociation> maillistAssociations = new HashSet<MaillistAssociation>();
.
.
.
}
I use an abstract HibernateDAO class from which i inherit all other DAO's and where i have a method to get the SessionFactory and the currentSession.
Any ideas what the cause of this exception could be?
[/code]