These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: JPA-compliant (I think) but complaining about Interfaces
PostPosted: Tue Nov 23, 2010 3:26 pm 
Newbie

Joined: Tue Nov 23, 2010 2:47 pm
Posts: 3
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-1896

I 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/impl

Given 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?


Top
 Profile  
 
 Post subject: Re: JPA-compliant (I think) but complaining about Interfaces
PostPosted: Wed Nov 24, 2010 11:17 am 
Newbie

Joined: Tue Nov 23, 2010 2:47 pm
Posts: 3
I have a working version of the test app against Hibernate now.

The key change was that I was trying to use the Proxy annotation against @Entity annotated interfaces, when I should have been using the targetEntity property in the field/property annotations of my @Entity annotated concrete classes instead.

After the issues around the annotated objects were resolved by changing this approach I just had a few straightforward changes to persistence.xml to get Hibernate to get the right JDBC connection, use the Postgres dialect, and auto-create any missing tables...

For example this annotation on the 'folder' property of FileImpl - my _implementation_ of the File interface now works fine...

@Entity(name="file")
@Table(name="file")
public class FileImpl extends LocatableImpl implements File{
...

@ManyToOne(targetEntity = FolderImpl.class,cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
public Folder getFolder() {
return folder;
}

}

See the class in full at...
https://github.com/cefn/Spring-JPA-MVC- ... eImpl.java

Note this project is organised to satisfy Maven so the pom.xml detailing required jars and compile steps is in the project root at...
https://github.com/cefn/Spring-JPA-MVC- ... d115f91da/
...the java source tree root is at...
https://github.com/cefn/Spring-JPA-MVC- ... main/java/
...the working persistence metadata is at
https://github.com/cefn/Spring-JPA-MVC- ... stence.xml

I'm using maven-compile-plugin and a Maven project nature to build and run this in Eclipse, without any kind of the build-time enhancement weirdness that I had in OpenJPA.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.