I had my test application working to store and retrieve data using OpenJPA, but encountered such a major bug that I have lost confidence in the project...
https://issues.apache.org/jira/browse/OPENJPA-1896I thought I'd try to migrate to Hibernate, but I must be doing something which isn't core JPA, as the switch isn't seamless, with Hibernate complaining when the same strategy is used, as well as under a set of basic changes to respond to its error reports.
The overall App was designed to be super-simple just to explore JPA Persistence, and a snapshot is available on github.
Does anyone know how I can use the interfaces Filesystem,Folder,File defined in my App...
https://github.com/cefn/Spring-JPA-MVC- ... filesystem...alongside the concrete classes FilesystemImpl, FolderImpl and FileImpl, which are the annotated and persisted POJOS...
https://github.com/cefn/Spring-JPA-MVC- ... ystem/implGiven this was already working with OpenJPA my approach was simply to switch the persistence.xml to identify Hibernate as the provider, and call on that provider in my dependency injection in the same way I was doing with OpenJPA. I gather that Hibernate does not need an enhance step either, which made my life simpler.
Initially I get...
org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.cefn.filesystem.impl.FolderImpl.filesystem references an unknown entity: com.cefn.filesystem.Filesystem
...which wasn't an issue before. OpenJPA seemed to know how to create FilesystemImpl classes when needing to populate FolderImpl.filesystem, even though the fields are defined by reference to interface Filesystem not FilesystemImpl.
If I can't use interfaces, then many of the advantages of using Java are lost.
I tried a few ways to make Hibernate happy with the interfaces, including declaring @Proxy(proxyClass=Filesystem.class) on FilesystemImpl and so on through the simple set of POJOs to make the interface explicit, and adding the interface classes to the list in persistence.xml. It still complains that the interface class is unknown with the same error.
Following this, I tried to move the @Entity annotations to the interfaces themselves, (including an @Id annotation on the Locatable#getId() method an @MappedSuperclass annotated superinterface of Filesystem, Folder and File). Launching the application then dies with...
org.hibernate.AnnotationException: No identifier specified for entity: com.cefn.filesystem.Filesystem
...despite the fact that @Id is clearly annotating a @MappedSuperclass of the Filesystem interface.
Any ideas how I'm meant to approach persisting these simple three classes against their interfaces in a way which uses JPA (preferably not Hibernate-specific), and which Hibernate will like, starting with the interfaces and their concrete implementations as found in github?