2017-06-29 1 views
1

Ich versuche, eine Menge Daten in einer Abfrage mit Hibernate zu bekommen.@OneToMany Ursache Sammlung ist keiner Sitzung zugeordnet

Ich habe diese benannte Abfrage:

SELECT r FROM Reservationlight_SS r LEFT JOIN r.personne p WHERE 
    r.iDSport =:IDSport AND r.iDSaison =:IDSaison AND 
    r.dateReservation =:date GROUP BY r.numeroReservation, r.heureDebutReservation, r.iDTerrain 

Als ich "JOIN" insted "LEFT JOIN" Ich benutze habe nur dieses Spiel r.personne rudern. Aber manchmal ist r.personne null. Also entscheide ich, die „LEFT JOIN“ zu verwenden und Hibernate geben Sie mir diesen Fehler:

org.hibernate.HibernateException: collection is not associated with any session 

Ich versuche zu suchen, wenn es möglich ist, die @OneToMany als optional zu haben, aber das ist nicht möglich. Aber ich bin mir ziemlich sicher, dass es ein Weg sein könnte, das nicht zu tun?

Dies ist meine Beziehung in meinem Code jetzt:

@OneToMany(fetch = FetchType.EAGER) 
@OrderBy(value = "NumReservation") 
@JoinColumns({ 
    @JoinColumn(name="NumReservation", referencedColumnName="NumeroReservation") 
}) 
private List<Personnereservationlight> personne; 

ich Erfolg alle Reservationlight_SS ohne personne zu haben, indem die „JOIN“ Löschen und auch Erfolg alle Reservationlight_SS zu haben, die eine r.personne in der haben andere Tabelle mit dem "JOIN". Aber ich kann die beiden nicht in derselben Anfrage haben, wenn ich die "LINKE VERBINDUNG" lege.

Jemand hat eine Idee?

Vielen Dank für Ihre Hilfe

Stapelüberwachung:

Infos: org.hibernate.HibernateException: collection is not associated with any session 
Avertissement: A system exception occurred during an invocation on EJB ReservationFacade, method: public java.util.List ch.plugin.plugin.dao.ReservationFacade.getAllReservationByDate(java.lang.Integer,java.lang.Integer,java.util.Date) 
Avertissement: javax.ejb.TransactionRolledbackLocalException: Client's transaction aborted 
    at com.sun.ejb.containers.EJBContainerTransactionManager.useClientTx(EJBContainerTransactionManager.java:357) 
    at com.sun.ejb.containers.EJBContainerTransactionManager.preInvokeTx(EJBContainerTransactionManager.java:251) 
    at com.sun.ejb.containers.BaseContainer.preInvokeTx(BaseContainer.java:4524) 
    at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1986) 
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:210) 
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88) 
    at com.sun.proxy.$Proxy10505.getAllReservationByDate(Unknown Source) 
    at ch.plugin.plugin.BusinessService.ReservationManager.getAllReservationByDate(ReservationManager.java:797) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081) 
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153) 
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786) 
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) 
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) 
    at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46) 
    at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52) 
    at sun.reflect.GeneratedMethodAccessor2154.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) 
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) 
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163) 
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140) 
    at sun.reflect.GeneratedMethodAccessor2155.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) 
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369) 
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758) 
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746) 
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212) 
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88) 
    at com.sun.proxy.$Proxy10481.getAllReservationByDate(Unknown Source) 
    at service.ReservationFacadeREST.getAllReservationByDate(ReservationFacadeREST.java:281) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081) 
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153) 
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786) 
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) 
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) 
    at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46) 
    at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52) 
    at sun.reflect.GeneratedMethodAccessor2154.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) 
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) 
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163) 
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140) 
    at sun.reflect.GeneratedMethodAccessor2155.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) 
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369) 
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758) 
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746) 
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212) 
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88) 
    at com.sun.proxy.$Proxy10551.getAllReservationByDate(Unknown Source) 
    at service.__EJB31_Generated__ReservationFacadeREST__Intf____Bean__.getAllReservationByDate(Unknown Source) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) 
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151) 
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:171) 
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:195) 
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104) 
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:387) 
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:331) 
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:103) 
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:271) 
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) 
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) 
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315) 
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297) 
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267) 
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297) 
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:254) 
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028) 
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:372) 
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381) 
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344) 
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221) 
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) 
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) 
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) 
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) 
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282) 
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) 
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) 
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201) 
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175) 
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) 
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) 
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) 
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) 
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) 
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) 
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) 
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561) 
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) 
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) 
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) 
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) 
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565) 
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545) 
    at java.lang.Thread.run(Thread.java:745) 

Entity:

@Entity 
@Table(name = "reservationlight") 
@XmlRootElement 
@NamedQueries({ 
    @NamedQuery(name = "getAllReservationByDateSS", query = "SELECT r FROM Reservationlight_SS r LEFT JOIN r.personne p WHERE r.iDSport =:IDSport AND r.iDSaison =:IDSaison AND r.dateReservation =:date GROUP BY r.numeroReservation, r.heureDebutReservation, r.iDTerrain") 
}) 
public class Reservationlight_SS implements Serializable { 
    private static final long serialVersionUID = 1L; 
    @Id 
    @Column(name = "DateReservation") 
    @Temporal(TemporalType.DATE) 
    private Date dateReservation; 
    @Id 
    @Column(name = "HeureDebutReservation") 
    @Temporal(TemporalType.TIME) 
    private Date heureDebutReservation; 
    @Id 
    @Column(name = "IDTerrain") 
    private int iDTerrain; 
    @Size(max = 7) 
    @Column(name = "CouleurReservation") 
    private String couleurReservation; 
    @Column(name = "NumeroReservation") 
    private Integer numeroReservation; 
    @Id 
    @Column(name = "IDSport") 
    private int iDSport; 
    @Id 
    @Column(name = "IDSaison") 
    private int iDSaison; 
    @Column(name = "IDCours") 
    private Integer IDCours; 
    @Column(name = "isPaye") 
    private int isPaye; 
    @Column(name = "Etat") 
    private boolean etat; 
    @Size(max = 25) 
    @Column(name = "Nom") 
    private String nom; 
    @Size(max = 25) 
    @Column(name = "Prenom") 
    private String prenom; 
    @Column(name = "IDUser") 
    private Integer iDUser; 
    @Column(name = "IDPersonne") 
    private Integer iDPersonne; 
    @Size(max = 65535) 
    @Column(name = "Texte") 
    private String texte; 
    @Column(name = "Prix") 
    private float prix; 
    @Size(max = 65535) 
    @Column(name = "Notification") 
    private String notification; 
    @Column(name = "JEtat") 
    private String jEtat; 
    @ManyToOne(optional = true) 
    @JoinColumns({ 
     @JoinColumn(name="IDRecurrence", referencedColumnName="IDRecurrence"), 
    }) 
    private Recurrencelight recurrence; 
    @OneToMany(fetch = FetchType.EAGER) 
    @OrderBy(value = "NumReservation") 
    @JoinColumns({ 
     @JoinColumn(name="NumReservation", referencedColumnName="NumeroReservation") 
    }) 
    private List<Personnereservationlight> personne; 

    public Reservationlight_SS() { 
    } 

    public Reservationlight_SS(Reservationlight_SS rh) 
    { 
     this.IDCours = rh.getIDCours(); 
     this.couleurReservation = rh.getCouleurReservation(); 
     this.dateReservation = rh.getDateReservation(); 
     this.etat = rh.getEtat(); 
     this.heureDebutReservation = rh.getHeureDebutReservation(); 
     this.iDPersonne = rh.getIDPersonne(); 
     this.iDSaison = rh.getIDSaison(); 
     this.iDSport = rh.getIDSport(); 
     this.iDTerrain = rh.getIDTerrain(); 
     this.iDUser = rh.getIDUser(); 
     this.isPaye = rh.getIsPaye(); 
     this.jEtat = rh.getjEtat(); 
     this.nom = rh.getNom(); 
     this.prenom = rh.getPrenom(); 
     this.notification = rh.getNotification(); 
     this.numeroReservation = rh.getNumeroReservation(); 
     this.prix = rh.getPrix(); 
     this.texte = rh.getTexte(); 
     this.recurrence = rh.getRecurrence(); 
     this.personne = rh.getPersonne(); 
    } 

    public Date getDateReservation() { 
     return dateReservation; 
    } 

    public void setDateReservation(Date dateReservation) { 
     this.dateReservation = dateReservation; 
    } 

    public Date getHeureDebutReservation() { 
     return heureDebutReservation; 
    } 

    public void setHeureDebutReservation(Date heureDebutReservation) { 
     this.heureDebutReservation = heureDebutReservation; 
    } 

    public int getIDTerrain() { 
     return iDTerrain; 
    } 

    public void setIDTerrain(int iDTerrain) { 
     this.iDTerrain = iDTerrain; 
    } 

    public String getCouleurReservation() { 
     return couleurReservation; 
    } 

    public void setCouleurReservation(String couleurReservation) { 
     this.couleurReservation = couleurReservation; 
    } 

    public Integer getNumeroReservation() { 
     return numeroReservation; 
    } 

    public void setNumeroReservation(Integer numeroReservation) { 
     this.numeroReservation = numeroReservation; 
    } 

    public int getIDSport() { 
     return iDSport; 
    } 

    public void setIDSport(int iDSport) { 
     this.iDSport = iDSport; 
    } 

    public int getIDSaison() { 
     return iDSaison; 
    } 

    public void setIDSaison(int iDSaison) { 
     this.iDSaison = iDSaison; 
    } 

    public Recurrencelight getRecurrence() { 
     return recurrence; 
    } 

    public void setRecurrence(Recurrencelight recurrence) { 
     this.recurrence = recurrence; 
    } 

    public Integer getIDCours() { 
     return IDCours; 
    } 

    public void setIDCours(Integer IDCours) { 
     this.IDCours = IDCours; 
    } 

    public int getIsPaye() { 
     return isPaye; 
    } 

    public void setIsPaye(int isPaye) { 
     this.isPaye = isPaye; 
    } 

    public boolean getEtat() { 
     return etat; 
    } 

    public void setEtat(boolean etat) { 
     this.etat = etat; 
    } 

    public String getNom() { 
     return nom; 
    } 

    public void setNom(String nom) { 
     this.nom = nom; 
    } 

    public String getPrenom() { 
     return prenom; 
    } 

    public void setPrenom(String prenom) { 
     this.prenom = prenom; 
    } 

    public Integer getIDUser() { 
     return iDUser; 
    } 

    public void setIDUser(Integer iDUser) { 
     this.iDUser = iDUser; 
    } 

    public Integer getIDPersonne() { 
     return iDPersonne; 
    } 

    public void setIDPersonne(Integer iDPersonne) { 
     this.iDPersonne = iDPersonne; 
    } 

    public String getTexte() { 
     return texte; 
    } 

    public void setTexte(String texte) { 
     this.texte = texte; 
    } 

    public float getPrix() { 
     return prix; 
    } 

    public void setPrix(float prix) { 
     this.prix = prix; 
    } 

    public String getNotification() { 
     return notification; 
    } 

    public void setNotification(String notification) { 
     this.notification = notification; 
    } 

    public String getjEtat() { 
     return jEtat; 
    } 

    public void setjEtat(String jEtat) { 
     this.jEtat = jEtat; 
    } 

    public List<Personnereservationlight> getPersonne() { 
     return personne; 
    } 

    @Transactional 
    public void setPersonne(List<Personnereservationlight> personne) { 
     this.personne = personne; 
    } 

    @Override 
    public int hashCode() { 
     int hash = 3; 
     hash = 17 * hash + Objects.hashCode(this.dateReservation); 
     hash = 17 * hash + Objects.hashCode(this.heureDebutReservation); 
     hash = 17 * hash + this.iDTerrain; 
     hash = 17 * hash + this.iDSport; 
     hash = 17 * hash + this.iDSaison; 
     return hash; 
    } 

    @Override 
    public boolean equals(Object obj) { 
     if (obj == null) { 
      return false; 
     } 
     if (getClass() != obj.getClass()) { 
      return false; 
     } 
     final Reservationlight_SS other = (Reservationlight_SS) obj; 
     if (!Objects.equals(this.dateReservation, other.dateReservation)) { 
      return false; 
     } 
     if (!Objects.equals(this.heureDebutReservation, other.heureDebutReservation)) { 
      return false; 
     } 
     if (this.iDTerrain != other.iDTerrain) { 
      return false; 
     } 
     if (this.iDSport != other.iDSport) { 
      return false; 
     } 
     if (this.iDSaison != other.iDSaison) { 
      return false; 
     } 
     return true; 
    } 

    @Override 
    public String toString() { 
     return "Reservationlight_SS{" + "dateReservation=" + dateReservation + ", heureDebutReservation=" + heureDebutReservation + ", iDTerrain=" + iDTerrain + ", couleurReservation=" + couleurReservation + ", numeroReservation=" + numeroReservation + ", iDSport=" + iDSport + ", iDSaison=" + iDSaison + ", isPaye=" + isPaye + ", etat=" + etat + ", nom=" + nom + ", prenom=" + prenom + ", iDUser=" + iDUser + ", iDPersonne=" + iDPersonne + ", texte=" + texte + ", prix=" + prix + ", notification=" + notification + '}'; 
    } 

} 

-Code die Ausnahme werfen: JTA

@Stateless 
public class ReservationFacade extends AbstractFacade<Reservation> implements ReservationFacadeLocal { 
    @EJB 
    EntityMan EntityMan; 

    protected EntityManager getEntityManager() { 
     return EntityMan.getEM(); 
    } 

    public ReservationFacade() { 
     super(Reservation.class); 
    } 

    public List<Reservationlight_SS> getAllReservationByDate(Integer idSport, Integer idSaison, Date date) { 
     try{ 
      return getEntityManager().createNamedQuery("getAllReservationByDateSS").setParameter("IDSport", idSport).setParameter("IDSaison", idSaison).setParameter("date", date).getResultList(); 
     }catch(Throwable th){ 
      System.out.println(th.getMessage()); 
      throw new SportReservExceptions(getClass().getName() + " -> " + th); 
     } 
    } 

}

+1

Wenn Sie nach einer Ausnahme fragen, geben Sie immer die vollständige Stack-Ablaufverfolgung der Ausnahme und den Code ein, der die Ausnahme verursacht. –

+1

Es wäre hilfreich, Ihren gesamten relevanten Code einschließlich der namedQuery-Definition zu teilen. –

+0

Vielen Dank für Ihre Hilfe, wie Sie sehen können, bearbeite ich, um den ganzen Code hinzuzufügen, aber ich glaube nicht, dass es mehr Hilfe gibt: D – Chatis

Antwort

1

In den meisten Fällen Ausnahme

org.hibernate.HibernateException: collection is not associated with any session 

zeigen Sie, dass Sie Sammlung versuchen zu ändern, ohne Transaktion, und feste beispielsweise folgenden Code

@Transactional 
public ... methodToChangeCollection(...) { 
    // you code 
} 

Weitere Info, see oder this

-Update :

Sie könnten versuchen Transaktion manuell zu verwenden, zum Beispiel:

public List<Reservationlight_SS> getAllReservationByDate(Integer idSport, Integer idSaison, Date date) { 
     try{ 
      EntityManager em = getEntityManager(); 
      em.getTransaction().begin(); 
      List<Reservationlight_SS> result = em.createNamedQuery("getAllReservationByDateSS").setParameter("IDSport", idSport).setParameter("IDSaison", idSaison).setParameter("date", date).getResultList(); 
      em.getTransaction().commit(); 
      return result; 
     }catch(Throwable th){ 
      System.out.println(th.getMessage()); 
      throw new SportReservExceptions(getClass().getName() + " -> " + th); 
     } 
    } 
+0

Vielen Dank für Ihre Hilfe, ich stelle meine volle Einheit dort und Sie können siehe Ich füge die Anmerkung hinzu, wie Sie mir raten, aber das funktioniert immer noch nicht :-( – Chatis

+0

Ich aktualisiere meine Antwort –

+0

Ich habe diesen Fehler jetzt: Ein JTA EntityManager kann getTransaction() nicht verwenden – Chatis

1

Soweit ich das beurteilen kann, Ihre Entity Reservationlight_SS ist nicht der Besitzer der Beziehung. Dies bedeutet, dass Ihre Tabelle für die Entität Personnereservationlight einen Fremdschlüssel für Reservationlight_SS hat. In diesem Fall möchten Sie wahrscheinlich mappedBy element with the OneToMany annotation verwenden.

Wenn Sie Spring verwenden, dann möchten Sie auch das transaction management is properly setup in Ihrer Konfiguration mit @EnableTransactionManagement oder <tx:annotation-driven/> überprüfen.

+0

Ich benutze nicht Spring: D – Chatis

+0

und die Verwendung der 'mappedBy' hat das gleiche Problem:' org.hibernate.HibernateException: Sammlung ist nicht mit einer Sitzung verbunden ' Und 'Personnererservationlight' ist ein Ansicht und keine Tabelle, also kein Fremdschlüssel für ... Aber Sie sind sicher, dass eine Beziehung @ OneToMany leer sein könnte? – Chatis

+0

Ihr Update mit Annotation '@ JoinTable' gibt an, dass Sie eine separate DB-Tabelle für die Beziehung haben. Ist das wirklich der Fall? Wenn nicht, dann ist dies der Grund, warum Ihre SQL-Abfrage nicht wie erwartet ist. –

Verwandte Themen