I am getting an error with a oneToMany association when using annotations with gilead for hibernate through gwt
Asked Answered
J

4

8

I'm using Gilead to persist my entities in my GWT project, im using hibernate annotations aswell. my problem is on my onetomany association.this is my User class that holds a reference to a list of FileLocations

@Entity
@Table(name = "yf_user_table")
public class YFUser implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "user_id",nullable = false)
private int userId;
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@Column(name = "email")
private String email;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name="USER_ID") private List fileLocations = new ArrayList();

This is my file location class

@Entity
@Table(name = "fileLocationTable")
public class FileLocation implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "locationId", updatable = false, nullable = false)
private int ieId;
@Column (name = "location")
private String location;

@ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="USER_ID", nullable=false) private YFUser uploadedUser;

When i persist this data in a normal desktop application, it works fine , creates the tables and i can add and store data to it. but when i try to persist the data in my gwt application i get errors i will show them lower. this is my ServiceImpl class that extends PersistentRemoteService.

public class TestServiceImpl extends PersistentRemoteService implements TestService {

public static final String SESSION_USER = "UserWithinSession";

public TestServiceImpl(){

    HibernateUtil util = new HibernateUtil();
        util.setSessionFactory(com.example.server.HibernateUtil
                .getSessionFactory());

    PersistentBeanManager pbm = new PersistentBeanManager();
    pbm.setPersistenceUtil(util);
    pbm.setProxyStore(new StatelessProxyStore());

    setBeanManager(pbm);
}

    @Override
public String registerUser(String username, String password, String email) {
    Session session = com.example.server.HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();

    YFUser newUser = new YFUser();
    newUser.setUsername(username);newUser.setPassword(password);newUser.setEmail(email);

    session.save(newUser);
    session.getTransaction().commit();

    return "Thank you For registering "+ username;

}

this is the error that im am getting. the error goes away when i remove my onetoManyRelationship and builds my session factory when i put it in , it on the line of buildsessionfactory in hibernate Util that it throws this exception. my hibernate util class is ok also. this is the error java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z

Mar 24, 2010 10:03:22 PM org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.5.0-Beta-4
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.5.0-Beta-4
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Mar 24, 2010 10:03:22 PM org.hibernate.annotations.common.Version <clinit>
INFO: Hibernate Commons Annotations 3.2.0-SNAPSHOT
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.search.HibernateSearchEventListenerRegister             enableHibernateSearch
INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the     classpath. Hibernate Search is not enabled.
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: com.example.client.Entity1
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity com.example.client.Entity1 on table entityTable1
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: com.example.client.YFUser
Mar 24, 2010 10:03:22 PM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity com.example.client.YFUser on table yf_user_table
Initial SessionFactory creation failed.java.lang.NoSuchMethodError:     javax.persistence.OneToMany.orphanRemoval()Z
[WARN] Nested in javax.servlet.ServletException: init:
java.lang.ExceptionInInitializerError
at com.example.server.HibernateUtil.<clinit>(HibernateUtil.java:38)
at com.example.server.TestServiceImpl.<init>(TestServiceImpl.java:29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39 )
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:463)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
at  org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1642)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:772)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:629)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:350)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1373)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:973)
at com.example.server.HibernateUtil.<clinit>(HibernateUtil.java:33)
... 26 more
[WARN] Nested in java.lang.ExceptionInInitializerError:
java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
at    org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1642)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:772)
at  org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:629)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:350)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1373)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:973)
at com.example.server.HibernateUtil.<clinit>(HibernateUtil.java:33)
at com.example.server.TestServiceImpl.<init>(TestServiceImpl.java:29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:463)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Junker answered 24/3, 2010 at 22:49 Comment(5)
The embedded Jetty that comes with GWT can be a PITA to configure (see #2364629). I'd switch to an external Java server (possibly the one you'll be using in production) and see if the errors/exceptions persist. For more info see code.google.com/webtoolkit/doc/latest/…Alleras
so i switched to the tomcat deployer , but now i am getting the problem that my application needs to be recompiled, all i did was take the war file for my gwt projwctand placed it in in web apps dir, any reason why?Junker
Yes, read carefully the docs I've linked above - see step #4. You need put the contents of the war folder in the webapps dir, not the war file (note: you'll only have to do this once).Alleras
yup i did this and i found the only way to get it working was to place this at the end of my url ?gwt.codesvr=:9997, this works fine, but my application still throughs the same error, the error is giving me information on an method not found exeception on an . orphanRemoval() method that is javax.peristence. would you have any idea from the above error why it is not working. if i remove my oneToMany association, the error goes away but it is limiting me to functionality that i can provide. is there a work around?Junker
Are you sure it's using the Tomcat instance? Is the stack trace still the same?Alleras
R
13

Deleting ejb3-persistance.jar and removing it from build path solved my problem, it may work for you too.

Also don't forget to add hibernate-jpa-2.0-api-1.0.0.Final.jar to your build path.

Retardant answered 6/4, 2010 at 16:52 Comment(1)
Yet another anything-but-seamless-upgrade experience. Thanks for the tip!Genagenappe
A
4

use javax.persistence api 2.0, but not 1.0 one

Anonym answered 4/4, 2010 at 16:53 Comment(1)
which can be downloaded from the sun repos at: download.java.net/maven/2/org/eclipse/persistence/… and then installed with: mvn install:install-file -DgroupId=javax.persistence -DartifactId=persistence-api -Dversion=2.0.0 -Dpackaging=jar -Dfile=path/to/the/downloaded/file.jarRandyranee
S
2

Just adding a comment to possibly help others facing this. It could also be that your application server provides a version of JPA that "overshadows" the hibernate version. For me I had to do something like this:

mkdir /usr/local/resin/libremoved
mv /usr/local/resin/lib/jpa* /usr/local/resin/libremoved/

Sulfanilamide answered 28/8, 2010 at 18:32 Comment(0)
V
0

Also if you're compiling with a "complete" Java EE API library (e.g. one that contains both JPA and other APIs such as Servlet etc) then make sure the complete library is further down the classpath than the specific JPA 2.0 library

Vowelize answered 15/10, 2010 at 11:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.