当使用gilead注释通过gwt进行hibernate时,我收到了与oneToMany关联的错误

时间:2010-03-24 22:49:46

标签: java hibernate gwt annotations gilead

我正在使用Gilead将我的实体持久化到我的GWT项目中,我也使用了hibernate注释。我的问题出在我的onetomany association.t这是我的User类,它包含对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(名称= “USER_ID”)     private List fileLocations = new ArrayList();

这是我的文件位置类

@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(取= FetchType.LAZY)     @JoinColumn(name =“USER_ID”,nullable = false)     私人YFUser uploadedUser;

当我将这些数据保存在普通的桌面应用程序中时,它可以正常工作,创建表格,我可以添加和存储数据。但是当我试图在我的gwt应用程序中保留数据时,我会收到错误,我会将它们显示得更低。这是我的ServiceImpl类,它扩展了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;

}

这是我得到的错误。当我删除我的onetoManyRelationship并构建我的会话工厂时,当我把它放入时,错误就消失了,它在hibernate Util的buildsessionfactory行中它抛出了这个异常。我的hibernate util类也可以。这是错误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)

4 个答案:

答案 0 :(得分:13)

删除ejb3-persistance.jar并从构建路径中删除它解决了我的问题,它也可能适合您。

另外,请不要忘记将hibernate-jpa-2.0-api-1.0.0.Final.jar添加到构建路径中。

答案 1 :(得分:4)

使用javax.persistence api 2.0,但不是1.0一个

答案 2 :(得分:2)

只需添加评论即可帮助其他人面对此问题。也可能是您的应用程序服务器提供了一个“遮盖”hibernate版本的JPA版本。对我来说,我必须做这样的事情:

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

答案 3 :(得分:0)

此外,如果您正在使用“完整”Java EE API库(例如,包含JPA和其他API(如Servlet等)的库)进行编译,那么请确保完整的库位于类路径的下方,而不是特定的JPA 2.0库