limitations of Hibernate
Serialization issue
I have found that my Hibernate’s entities are working fine only when I am using them locally by jsp-es or servlets.
Unfortunately my goal was to connect thick client to server. That time I was using flex 3 to build client and AMF3 protocol with weborb to invoke remote methods on my Spring’s beans. The problem I run into was that I used lazy initialization in entities and while serializing LazyInitializationException is thrown. It is natural as I object is outside the transaction and something is getting data from entity.
It seems that it can be solved,
- by using OSIV filter(open session in view) – but really I don’t know if serialization will not fetch lazy initialized collections.
- by using custom object-queries to return a simple object or collection of objects rather than entity (look to JPA specification).
- by mapping entities with Dozer framework – in my opinion, it is not really promising for more complicated entities relationships with lazy, eager combinations.
I don’t have too much time now, so check it by yourself.
Fortunately for me I switch to java desktop application and there I can use spring’s HttpInvoker.
- http://blog.platinumsolutions.co.. and following part http://blog.platinumsolutions.co...
- http://…..spring-remoting-strategies-compared.html.
- http://….TheSpringExperienceSpringRemoting.pdf.
Extending entity issue
When creating hierarchy of entities that are stored in the same DB table, you need to be careful with relationships between them. I don’t know why, but Hibernate is not always using @DiscriminatorColumn flag to filter data set and that is violating Collection type.
Take care.
styczeń 29, 2008 @ 6:56 pm
Even with custom object queries, you will still not be able to serialize hibernate proxies (hibernate proxifies collections for instance to track diry changes and enforce lazy fetc, etc). You can use OSIV and Dozer. Dozer works great if your DTO’s fields are exactly named as your EJB’s fields. It even identifies circular dependencies. Of course, using OSIV with dozer you’ll not get too much performance, and you’ll eventually fetch everything that’s not null, since dozer invokes getters and setters to reflectivy map one instance into another
styczeń 29, 2008 @ 7:16 pm
that is why Hibernate is just a toy, not really good thing for enterprise project. and saying truth if I need to eventually create queries anyway then it is not worth it.
Of course as long as serialization is a problem, if not YES USE it:)
styczeń 30, 2008 @ 11:01 pm
I’m too frustrated by the lack of documentation on how to correctly handle lazy relationships in wizard type (web) UIs. I’ve previously used Cayenne http://cayenne.apache.org/ to develop a Swing client/server application and I just never had to deal with these sort of issues.
Cayennes ObjectContext – I guess the closest equivalent to Hibernate’s Session is designed to work with long running conversations out of the box. I’m yet to find a decent explanation of how to setup session-per-conversation environment. Perhaps I just don’t fall into the mindset of a typical Hibernate user when it comes to reading their docs…
styczeń 31, 2008 @ 8:30 am
can you give some example on how to use that?