web-dev-qa-db-de.com

Die Sammlung konnte nicht faul initialisiert werden. Es wurde keine Sitzung geschlossen

Ich weiß nicht, was ich sonst noch probieren soll, ich habe ein Update auf Jackson 2 vorgenommen, in Lazy geändert, @JsonIgnore verwendet ..., aber nichts hat geklappt. Irgendeine Idee, was kann es sein?

Umgebung

  • Spring MVC 3.2.5
  • Jackson 2.2
  • Ruhezustand 3.5.4

ERROR Estado HTTP 500 - Konnte nicht geschrieben werden: JSON konnte nicht faul eine Sammlung von Rollen initialisieren: com.javalabs.web.dao.Task.actions. Es wurde keine Sitzung oder Sitzung geschlossen (durch Referenzkette: Java.util.HashMap ["Aktionen".) ] -> Java.util.ArrayList [0] -> com.javalabs.web.dao.TaskAction ["task"] -> com.javalabs.web.dao.Task ["actions"]); Die verschachtelte Ausnahmebedingung ist com.fasterxml.jackson.databind.JsonMappingException: Die Sammlung einer Rolle konnte nicht faul initialisiert werden: com.javalabs.web.dao.Task.actions. Keine Sitzung oder Sitzung wurde geschlossen (über Referenzkette: Java.util.HashMap.) ["Aktionen"] -> Java.util.ArrayList [0] -> com.javalabs.web.dao.TaskAction ["Task"] -> com.javalabs.web.dao.Task ["Aktionen"])

Fehlerspur

org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: failed to lazily initialize a collection of role: com.javalabs.web.dao.Task.actions, no session or session was closed (through reference chain: Java.util.HashMap["actions"]->Java.util.ArrayList[0]->com.javalabs.web.dao.TaskAction["task"]->com.javalabs.web.dao.Task["actions"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: com.javalabs.web.dao.Task.actions, no session or session was closed (through reference chain: Java.util.HashMap["actions"]->Java.util.ArrayList[0]->com.javalabs.web.dao.TaskAction["task"]->com.javalabs.web.dao.Task["actions"])
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.writeInternal(MappingJackson2HttpMessageConverter.Java:207)
org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.Java:179)
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.Java:148)
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.Java:90)
org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.Java:189)
org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.Java:69)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.Java:122)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.Java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.Java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.Java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.Java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.Java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.Java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.Java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.Java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.Java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.Java:727)
org.Apache.Tomcat.websocket.server.WsFilter.doFilter(WsFilter.Java:52)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.Java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.Java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.Java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.Java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.Java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.Java:154)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.Java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.Java:199)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.Java:110)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.Java:50)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.Java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.Java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.Java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.Java:343)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.Java:260)
causa raíz

com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: com.javalabs.web.dao.Task.actions, no session or session was closed (through reference chain: Java.util.HashMap["actions"]->Java.util.ArrayList[0]->com.javalabs.web.dao.TaskAction["task"]->com.javalabs.web.dao.Task["actions"])
com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.Java:232)
com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.Java:197)
com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.Java:184)
com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:605)
com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:142)
com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:569)
com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:597)
com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:142)
com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.Java:100)
com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.Java:21)
com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.Java:186)
com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.Java:394)
com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.Java:315)
com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.Java:27)
com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.Java:118)
com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.Java:1819)
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.writeInternal(MappingJackson2HttpMessageConverter.Java:204)
org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.Java:179)
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.Java:148)
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.Java:90)
org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.Java:189)
org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.Java:69)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.Java:122)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.Java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.Java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.Java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.Java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.Java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.Java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.Java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.Java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.Java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.Java:727)
org.Apache.Tomcat.websocket.server.WsFilter.doFilter(WsFilter.Java:52)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.Java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.Java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.Java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.Java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.Java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.Java:154)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.Java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.Java:199)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.Java:110)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.Java:50)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.Java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.Java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.Java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.Java:343)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.Java:260)
causa raíz

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.javalabs.web.dao.Task.actions, no session or session was closed
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.Java:383)
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.Java:375)
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.Java:368)
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.Java:111)
org.hibernate.collection.PersistentBag.iterator(PersistentBag.Java:272)
com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:90)
com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:23)
com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.Java:186)
com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:569)
com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:597)
com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:142)
com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:569)
com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:597)
com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:142)
com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.Java:100)
com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.Java:21)
com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.Java:186)
com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.Java:394)
com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.Java:315)
com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.Java:27)
com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.Java:118)
com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.Java:1819)
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.writeInternal(MappingJackson2HttpMessageConverter.Java:204)
org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.Java:179)
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.Java:148)
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.Java:90)
org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.Java:189)
org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.Java:69)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.Java:122)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.Java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.Java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.Java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.Java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.Java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.Java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.Java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.Java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.Java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.Java:727)
org.Apache.Tomcat.websocket.server.WsFilter.doFilter(WsFilter.Java:52)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.Java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.Java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.Java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.Java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.Java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.Java:154)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.Java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.Java:199)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.Java:110)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.Java:50)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.Java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.Java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.Java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.Java:343)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.Java:260)

MODEL

enter image description here

TaskController.Java

@Controller
public class TaskController {

...

    @RequestMapping(value = "/getactions/{id}", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody Map<String, Object> getActions(Principal principal,
            @PathVariable Long id) {
        logger.info("Task controller get actions...");

        List<TaskAction> actions = null;

        if (principal == null) {
            actions = new ArrayList<TaskAction>();
        } else {
            actions = taskActionService.getAllTaskActions(id);
        }

        Map<String, Object> data = new HashMap<String, Object>();
        data.put("actions", actions);
        data.put("number", actions.size());

        return data;
    }
}

Task.Java

@Entity
@Table(name = "t_task")
public class Task {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "idTask")
    private long idTask;
    @Size(min = 5, max = 100)
    @Column(name = "taskname")
    private String taskname;
    ...
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "task", orphanRemoval = true)
    private List<TaskAction> actions = new ArrayList<TaskAction>();
    @Column(name = "timestamp")
    private Timestamp timestamp;
...
}

User.Java @ Entity @ Table (name = "t_user") Public Klasse User {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "idUser")
private long idUser;

...

@ManyToMany(cascade = { CascadeType.ALL })
@JsonIgnore
@JoinTable(name = "r_userrole", joinColumns = { @JoinColumn(name = "idUser") }, inverseJoinColumns = { @JoinColumn(name = "idRole") })
private Set<Role> roles = new HashSet<Role>();

...}

TaskAction.Java

@Entity
@Table(name = "t_taskaction")
public class TaskAction {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "idTaskAction")
    private long idTaskAction;
    @ManyToOne
    @JoinColumn(name = "idTask", nullable = false)
    private Task task;
    ...
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "idUser", nullable = false)
    private User user;
    @Column(name = "timestamp")
    private Date timestamp;
    ...
}

TaskActionDao.Java

@Repository
@Transactional
@Component("taskActionDao")
public class TaskActionDao {

    @Autowired
    private SessionFactory sessionFactory;

    public Session session() {
        return sessionFactory.getCurrentSession();
    }

    ...

    @SuppressWarnings("unchecked")
    public List<TaskAction> getAllTaskActions() {
        Query q = session().createQuery("from TaskAction");
        List<TaskAction> la = q.list();
        //createQuery("from TaskAction").list();
        System.out.println(">>>>>>>>>>getAllActions>>>>>>>>>>> " + la.size());
        return la;
    }

    @SuppressWarnings("unchecked")
    public List<TaskAction> getAllTaskActions(long idTask) {
        Criteria crit = session().createCriteria(TaskAction.class);
        crit.add(Restrictions.eq("task.idTask", idTask));
        System.out.println(">>>>>>>>getAllActions(id)>>>>>>>>>>>>> " + crit.list().size());
        return crit.list();
    }
}
13
Joe

Vor allem brauchen wir User.Java hier überhaupt nicht. Es hat nichts zu tun. Das Problem bezieht sich auf Task.actions. Sie laden eine TaskAction-Sammlung, TaskAction hat Task und diese Task hat eine TaskAction-Sammlung, die nicht initialisiert werden kann. Sie können @JsonIgnore hinzufügen zu:

private List<TaskAction> actions = new ArrayList<TaskAction>(); //Task class

oder zu:

private Task task; //TaskAction class

Sie können auch versuchen, FetchType.LAZY in FetchType.EAGER für die Sammlung von Aktionen in Task.Java zu ändern.

15
maszter

Da Sie auf Ihr Objekt außerhalb des Objekts "Hibernate Session" zugreifen, sollten Sie die Annotation @JsonIgnore vor jeder @OneToMany-Anmerkung in Ihrem Modell hinzufügen

5
Tribuwan Singh

Fügen Sie die Annotation @JsonIgnore vor jeder @OneToMany-Annotation in Ihrer Entitätsklasse Meine Lösung hinzu 

@JsonIgnore
@OneToMany(cascade = CascadeType.ALL, mappedBy = "domainDataId")

Danke Shahid Hussain Abbasi

Ich hatte ein Problem mit der gleichen Ausnahme wie oben und klagte über "keine Sitzung". Ich stellte jedoch fest, dass das Problem darauf zurückzuführen war, dass die Entität in der DTO anstelle ihrer ID referenziert wurde. Wenn also das oben genannte Problem auftritt, schlage ich vor, zu überprüfen, ob ein Serialisierungsproblem nicht aufgetreten ist. 

0
Yoku

Ich habe kürzlich ein ähnliches Problem festgestellt: Jackson Version 1.9 und niedriger mit bidirektionalen Beziehungen (Zyklen vermeiden)

Die Lösung scheint ein Upgrade auf Jackson 2.0 durchzuführen und den Klassen die folgende Anmerkung hinzuzufügen:

@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, 
                  property = "idTaskAction")
public class TaskAction

Mehr Info

0
Joe