Salut
c`est un probleme de persistance et l`ajout des donnees
je suis débutant dans les notions de J EE et GlassFish , mais j`ai réussi a créer une application J2EE et de faire le déploiement de cette dernière dans le serveur d`application GlassFish et aussi j`ai tester une Méthodes que j`ai déjà crée et ça marche bien. Maintenant j`ai une base de données contient différent Tables , alors j`ai persister ces dernier et j`ai crée les différents méthodes de persistance et ceci grâce a l`Hibernate avec la création des connexion Pool , j`ai vérifiée aussi les différents jar qu`il faut utilisé et j`ai déjà ajouter , et j`ai crée aussi des fichier XML de persistance pour L`EJB et pour le Client,alors le problème ce que je peux pas accéder a la Base de donner pour modifier ou ajouter des champs .
je travaille sur NetBeans IDE 6.5 et mes bases sont avec MySQL.
toujours je peux pas accéder a la base de données et ajouter des nouveaux informations , j`ai fait les étapes qu`il faut faire mais toujours existe l`exception
aider moi s.v.p , je suis très déçus , et j`arrive pas a résoudre le problème , c `est presque 2 semaines et je suis dans le même problème
/******************************exception*********/
WARNING: ACC003: Application threw an exception.
javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: null; nested exception is:
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.wct.entity.Customer
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: null; nested exception is:
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.wct.entity.Customer
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:243)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:205)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152)
at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(BCELStubBase.java:225)
at com.wct.DAO.__DAORemote_Remote_DynamicStub.ajoutercustomet_test(com/wct/DAO/__DAORemote_Remote_DynamicStub.java)
at com.wct.DAO._DAORemote_Wrapper.ajoutercustomet_test(com/wct/DAO/_DAORemote_Wrapper.java)
at synchro_pfa.Main.main(Main.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:266)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:449)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:259)
at com.sun.enterprise.appclient.Main.main(Main.java:200)
Caused by: java.rmi.RemoteException: null; nested exception is:
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.wct.entity.Customer
at com.sun.enterprise.iiop.POAProtocolMgr.mapException(POAProtocolMgr.java:251)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1386)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:210)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:117)
at $Proxy37.ajoutercustomet_test(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:154)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:687)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:227)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1846)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1706)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1088)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:223)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:806)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:563)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2567)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
Caused by: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.wct.entity.Customer
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:226)
at com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:440)
at com.wct.DAO.DAOBean.ajoutercustomet_test(DAOBean.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:203)
... 17 more
Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.wct.entity.Customer
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:79)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)
... 28 more
javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: null; nested exception is:
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.wct.entity.Customer
at com.wct.DAO._DAORemote_Wrapper.ajoutercustomet_test(com/wct/DAO/_DAORemote_Wrapper.java)
at synchro_pfa.Main.main(Main.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:266)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:449)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:259)
at com.sun.enterprise.appclient.Main.main(Main.java:200)
Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:461)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:259)
at com.sun.enterprise.appclient.Main.main(Main.java:200)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:266)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:449)
... 2 more
Caused by: javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: null; nested exception is:
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.wct.entity.Customer
at com.wct.DAO._DAORemote_Wrapper.ajoutercustomet_test(com/wct/DAO/_DAORemote_Wrapper.java)
le code client est :
/********************************************/
package synchro_pfa;
import com.wct.DAO.*;
import com.wct.entity.*;
import com.wct.jpaController.*;
import java.rmi.RemoteException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.transaction.SystemException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
*
* @author Ziko
*/
public class Main {
//@EJB
private static DAORemote dao_remote;
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws NamingException {
InitialContext ctx;
try {
System.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
System.setProperty("java.naming.factory.url.pkgs","com.sun.enterprise.naming");
System.setProperty("java.naming.factory.state","com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
System.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
System.setProperty("org.omg.CORBA.ORBInitialPort", "5433");
ctx = new InitialContext();
Object ref = ctx.lookup("ejb/Synchro");
dao_remote=( DAORemote)PortableRemoteObject.narrow(ref,DAORemote.class);
dao_remote.ajoutercustomet_test(1,"nhgfd", "jhg");
javax.swing.JOptionPane.showMessageDialog(null,"ajout avec succes");
javax.swing.JOptionPane.showMessageDialog(null,dao_remote.hello("Mr Admin"));
// Customer cus = new Customer();
//cus.setName("test");
//cus.setDescr("inchalah");
//dao_remote.createCustomer(cus);
//javax.swing.JOptionPane.showMessageDialog(null,"Ajout avec succee");
}
catch (NamingException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
/************SessionBean est *************************/
package com.wct.DAO;
import com.wct.entity.Customer;
import com.wct.entity.Member1;
import com.wct.entity.Phase;
import com.wct.entity.Price;
import com.wct.entity.Project;
import com.wct.entity.Worklog;
import com.wct.entity.Workloghistory;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
*
* @author Ziko
*/
@Stateless(name="Sunchronisation", mappedName="ejb/Synchro")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class DAOBean implements DAORemote, DAOLocal {
@PersistenceContext(unitName="Synchro_PFA_ejbPU")
private EntityManager em;
public String hello(String name) {
return "Hello " + name;
}
/******************************Customer*************************************/
public List<Customer> findallCustomer() {
return em.createQuery("select object(o) from Customer as o").getResultList();
}
public void createCustomer(Customer customer) {
em.persist(customer);
}
public void editCustomer(Customer customer) {
em.merge(customer);
}
public void removeCustomer(Customer customer) {
em.remove(em.merge(customer));
}
public Customer findCust(Object id) {
return em.find(Customer.class, id);
}
public void ajoutercustomet_test(int id , String name, String descri){
Customer c = new Customer();
c.setIdCustomer(id);
c.setName(name);
c.setDescr(descri);
em.persist(c);
}
/***************************Project*****************************************/
public List<Project> findallProject() {
return em.createQuery("select object(o) from Project as o").getResultList();
}
public void createProject(Project project) {
em.persist(project);
}
public void editProject(Project project) {
em.merge(project);
}
public void removeProject(Project project) {
em.remove(em.merge(project));
}
public Project findProject(Object id) {
return em.find(Project.class, id);
}
/****************************Phase***************************************/
public List<Phase> findallPhase() {
return em.createQuery("select object(o) from Phase as o").getResultList();
}
public void createPhase(Phase phase) {
em.persist(phase);
}
public void editPhase(Phase phase) {
em.merge(phase);
}
public void removePhase(Phase phase) {
em.remove(em.merge(phase));
}
public Phase findPhase(Object id) {
return em.find(Phase.class, id);
}
/*****************************Price******************************************/
public List<Price> findallPrice() {
return em.createQuery("select object(o) from Price as o").getResultList();
}
public void createPrice(Price price) {
em.persist(price);
}
public void editPrice(Price price) {
em.merge(price);
}
public void removePrice(Price price) {
em.remove(em.merge(price));
}
public Price findPrice(Object id) {
return em.find(Price.class, id);
}
/****************************************************************************/
public List<Member1> findallMember1() {
return em.createQuery("select object(o) from Member1 as o").getResultList();
}
public void createMember1(Member1 member1) {
em.persist(member1);
}
public void editMember1(Member1 member1) {
em.merge(member1);
}
public void removeMember1(Member1 member1) {
em.remove(em.merge(member1));
}
public Member1 findMember1(Object id) {
return em.find(Member1.class, id);
}
/****************************************************************************/
public List<Worklog> findallWorklog() {
return em.createQuery("select object(o) from Worklog as o").getResultList();
}
public void createWorklog(Worklog worklog) {
em.persist(worklog);
}
public void editWorklog(Worklog worklog) {
em.merge(worklog);
}
public void removeWorklog(Worklog worklog) {
em.remove(em.merge(worklog));
}
public Worklog findWorklog(Object id) {
return em.find(Worklog.class, id);
}
/*******************************************************************************/
public List<Workloghistory> findallWorkloghistory() {
return em.createQuery("select object(o) from WorklogHistory as o").getResultList();
}
public void createWorkloghistory(Workloghistory worklogHistory) {
em.persist(worklogHistory);
}
public void editWorkloghistory(Workloghistory worklogHistory) {
em.merge(worklogHistory);
}
public void removeWorkloghistory(Workloghistory worklogHistory) {
em.remove(em.merge(worklogHistory));
}
public Workloghistory findWorkloghistory(Object id) {
return em.find(Workloghistory.class, id);
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add Operation")
}
/****************fichier de persistance*****************/
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="Synchro_PFA_ejbPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/Data_base_WCT_Z</jta-data-source>
<class>com.wct.entity.Customer</class>
<class>com.wct.entity.Member1</class>
<class>com.wct.entity.Phase</class>
<class>com.wct.entity.Price</class>
<class>com.wct.entity.Project</class>
<class>com.wct.entity.Worklog</class>
<class>com.wct.entity.Workloghistory</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/data_base_wct"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.username" value="root"/>
</properties>
</persistence-unit>
</persistence>
/***************Sun.xml**********************/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="jdbc/Data_base_WCT_Z" object-type="user" pool-name="WCT_DB_Pool">
<description/>
<property name="base_de_donnees_WCT" value="()"/>
</jdbc-resource>
<jdbc-resource enabled="true" jndi-name="jdbc/BACKUP_WCT_DB" object-type="user" pool-name="Backup_WCT_DB_Pool">
<description/>
<property name="Backup_DB_WCT" value="()"/>
</jdbc-resource>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="WCT_DB_Pool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="URL" value="jdbc:mysql://localhost:3306/data_base_wct"/>
<property name="User" value="root"/>
<property name="Password" value="()"/>
</jdbc-connection-pool>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="Backup_WCT_DB_Pool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="URL" value="jdbc:mysql://localhost:3306/backup_data_base"/>
<property name="User" value="root"/>
<property name="Password" value="()"/>
</jdbc-connection-pool>
</resources>
Configuration: Windows Vista
Firefox 3.0.7