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)
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.
use javax.persistence api 2.0, but not 1.0 one
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With