小编典典

将注释与gilead一起用于通过gwt进行休眠时,oneToMany关联出现错误

hibernate

我正在使用Gilead将我的实体保存在我的GWT项目中,同时还使用了hibernate注释。我的问题出在我的onetomany关联上。这是我的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(name
=“ USER_ID”)私有列表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(fetch = 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上抛出此异常。我的hibernateutil类也可以。这是错误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)

阅读 252

收藏
2020-06-20

共1个答案

小编典典

ejb3-persistance.jar从构建路径中删除和删除它可以解决我的问题,它也可能对您有用。

同样不要忘记添加hibernate-jpa-2.0-api-1.0.0.Final.jar到您的构建路径。

2020-06-20