I’m still new to using ORM stuff in Java, and here is one question I seem to be stuck on:
I have a large number of Hibernate Entities and want to query for them on the server (works fine) then serialise them (using ObjectOuputStream) and send them to a client.
If I deserialize them on the client there is still a large number of Hibernate / javax.persistence dependencies.
Is it possible to transform my entities to POJOs with no dependency on hibernate at all somehow?
Thanks!
EDIT:
To clear thing up, I am using annotations, which is probably silly. I will need to redefine all classes to be annotation-free, then they should be standard POJOs.
Yes, you just have to fall back to XML configuration as opposed to convenient annotations. Hibernate has its
hbmfiles from the very beginning, with JPA you useorm.xml.Every can be expressed with XML, annotations are only syntactic sugar. This way your entities will be absolutely free of Hibernate/
javax.persistencereferences.See also: JPA: Should I clean up my entity classes using orm.xml?
P.S.: Keep in mind that serializing your domain model (JPA/Hibernate entities) will prove to be a pain soon once you start refactoring your domain model. Even when you control both sides. Really, really consider DTOs.