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

Spring Controller annotated with @JsonView and hibernate4 #73

Open
bademux opened this issue Sep 8, 2015 · 5 comments
Open

Spring Controller annotated with @JsonView and hibernate4 #73

bademux opened this issue Sep 8, 2015 · 5 comments

Comments

@bademux
Copy link

bademux commented Sep 8, 2015

Hello,
It isn't a bug, bug nasty behavior.
I configure my MappingJackson2HttpMessageConverter for using ObjectMapper and Hibernate4Module with SessionFactory

Spring along @JsonView-aware Controller has been used
see for more info: "Jackson’s @JsonView is supported directly on @ResponseBody"

I supposed that all Lazy fields will be initiated and serialized, but got "could not initialize proxy - no Session" on

@ManyToOne(fetch = FetchType.LAZY, optional = false) 
private Test test;

exception goes from
com.fasterxml.jackson.datatype.hibernate4.HibernateProxySerializer#findProxied

return init.getImplementation(); 

Is it expected?

@cowtowncoder
Copy link
Member

The first question usually is whether you can reproduce the behavior without spring, just using Jackson and Hibernate module. My guess is that the problem is that Spring controller is trying to serialize things after Hibernate session is closed; if so, this is not something Jackson has any control over.

@bademux
Copy link
Author

bademux commented Sep 16, 2015

exactly, but Hibernate4 Jackson module trying to handle this (at least for Collections - check PersistentCollectionSerializer).
Let me ask it in other way:
Why only collection handled in such way? (I see here inconsistency with single reference, o at least undocumented behavioud)
Why hibernate session is opened per object property not per object itself?
Thanks.

@cowtowncoder
Copy link
Member

Jackson module does not open sessions as far as I recall. It assumes a session exists, during processing.

Having said that, I do not use Hibernate nor Spring, so someone else may have to help here.
I only help to maintain this module.

@bademux
Copy link
Author

bademux commented Sep 17, 2015

Session is opened by hibernate4module, added here: e4b3654 , see for more info:

PersistentCollectionSerializer#openTemporarySessionForLoading()

Hibernate module opens session for read for each collection, but ignoring simple refs.

Please, consider to mark it as a bug if you find inconsistency in the behavior.

cast @eoger :)

upd.
I think, it happens because HibernateSerializerModifier#modifySerializer() is commented out.
But not sure - investigation is needed.

btw, it is really bad approach to open session per property.It is responsibility of another abstraction layer, imho

@cowtowncoder
Copy link
Member

I stand corrected. Thank you for pointing this out @bademux.

And that does seem wrong to me as well, since it really ought not to be data-binding layer's responsibility.

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

No branches or pull requests

2 participants