"对象:beans.Utilisateur [idUtilisateur = null]不是已知的实体类型。"

时间:2017-02-01 22:36:54

标签: java-ee netbeans glassfish eclipselink jta

首先让我说我知道类似的问题已得到解答,但它们都没有完全符合我的问题。

我刚开始使用带有netbeans的JEE,带有glassfish服务器和postgresql数据库。我正在使用eclipseLink和jta交易。我有一些直接从我的数据库表中使用netbeans生成的实体类。当我尝试将条目添加到我的数据库表时,问题就出现了。我有一个名为UtilisateurFacade的ejb,应该添加一个新的" Utilisateur"到我的数据库,这里是:

@Stateless
public class UtilisateurFacade extends AbstractFacade<Utilisateur> {


@PersistenceContext(unitName = "LaCuillere-ejbPU")
private EntityManagerFactory emf;


@Override
protected EntityManager getEntityManager() {
    return emf.createEntityManager();
}

public UtilisateurFacade() {
    super(Utilisateur.class);
    emf=Persistence.createEntityManagerFactory("LaCuillere-ejbPU");

}
@Transactional
public Integer addUser(Utilisateur u) throws NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException{
    EntityManager em=getEntityManager();
    em.persist(u);
    em.flush();
    return u.getIdUtilisateur();

}
}

然后我在java类insertUser中调用addUser()

public class insertUser {

public static void addToDb(ArrayList<String> userDatas) throws NotSupportedException, SystemException, javax.transaction.RollbackException, HeuristicMixedException, HeuristicRollbackException, Exception
{

    Utilisateur u=new Utilisateur();
    u.setMail(userDatas.get(0));
    u.setNom(userDatas.get(1));
    u.setPrénom(userDatas.get(2));
    u.setProfil(userDatas.get(3));
    u.setPassword(userDatas.get(4));
    u.setTel(userDatas.get(5));

    UtilisateurFacade uf=new UtilisateurFacade();
    uf.addUser(u);


}

}

userDatas由从表单获取数据的servlet发送。 但是我得到了这个错误:

Grave:   java.lang.IllegalArgumentException: Object: beans.Utilisateur[ idUtilisateur=null ] is not a known Entity type.
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4226)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:507)
at beans.UtilisateurFacade.addUser(UtilisateurFacade.java:50)
at inserts.insertUser.addToDb(insertUser.java:37)
at servlets.getUserInfo.processRequest(getUserInfo.java:57)
at servlets.getUserInfo.doPost(getUserInfo.java:105)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)

这是我的persistence.xml,我尝试手动添加<class>beans.Utilisateur</class>,但是当它不在这里时,它已经给我错误了:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence    http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="LaCuillere-ejbPU" transaction-type="JTA">
    <jta-data-source>LaCuillereDB</jta-data-source>
    <class>beans.Utilisateur</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
      <property name="eclipselink.target-server" value="SunAS9"/>
    </properties>
  </persistence-unit>
</persistence>

0 个答案:

没有答案