Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NestedEntitySerializer fails to serialize Map for Hibernate proxy [DATAREST-897] #1266

Closed
spring-projects-issues opened this issue Sep 18, 2016 · 4 comments
Assignees
Labels
type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Sep 18, 2016

Petar Tahchiev opened DATAREST-897 and commented

Hello,

I have the following JPA entity which I want to expose via rest:


@Entity
public class ProductEntity {


    @ElementCollection(targetClass = LobValue.class)
    @CollectionTable(name = "s_name_lv", joinColumns = @JoinColumn(name = "s_pk"))
    @MapKeyColumn(name = "locale")
    private Map<String, LobValue> s;
    
    //getters/setters

}

where the LobValue is an embeddable:


@Embeddable
@Access(AccessType.FIELD)
public class LobValue {

    private String s;

    public String getS() {
        return s;
    }

    public void setS(String s) {
        this.s = s;
    }
}

However when I try to access http://localhost:8080/rest/productEntities from the browser I get the following exception:

Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, could not initialize proxy - no Session
	at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:579)
	at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:203)
	at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:558)
	at org.hibernate.collection.internal.PersistentMap.put(PersistentMap.java:163)
	at org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$NestedEntitySerializer.serialize(PersistentEntityJackson2Module.java:362)
	at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693)
	at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690)
	... 140 more

which happens when the PersistentEntityJackson2Module tries to serialize the json.

This code works perfectly fine with Gosling-SR4 but the exception happens with Hopper or Ingals.

Here's a sample repository that reproduces this behavioud:

http://github.com/ptahchiev/demo-rest-problem

Just start the project with mvn spring-boot:run and then navigate to http://localhost:8080/rest/productEntities.

P.S. I mark this with blocker because it blocks me to update to Hopper or Ingalls


Referenced from: commits bacd8be, 759ba86

Backported to: 2.5.3 (Hopper SR3)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 18, 2016

Oliver Drotbohm commented

Should be an easy fix as this seems to related to Spring's CollectionFactory using the native Hibernate type which in turn requires an active Session.

Generally speaking, we use priorities to indicate severance regarding the overall functionality of the library. Otherwise every ticket would be filed as blocker

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 19, 2016

Oliver Drotbohm commented

This should be fixed. You sample project (already set up to use snapshots) builds fine now

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 19, 2016

Oliver Drotbohm commented

Please give the snapshots a try. Also, sample projects are most helpful if they're as small as possible and contain a failing test case and then we can just run the build to verify the fix. Having to issue particular requests manually is suboptimal as introduces a lot of other vectors that could potentially cause issues

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 19, 2016

Petar Tahchiev commented

The latest SNAPSHOTs work fine. Thanks for the fix and the feedback - i'll try to create better sample projects from now on :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug
Projects
None yet
Development

No branches or pull requests

2 participants