Bonjour à tous,
J'essaye tout simplement d'insérer un objet dans une table nommé "personnes" avec persist de JPA. L'erreur vient lors de l'invocation du persit de mon OJB local "personServiceLocal".
Mon erreur :
Code client main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 Infos: file:/C:/Users/Bastien/Documents/NetBeansProjects/test/dist/gfdeploy/test/test-ejb_jar/-test-ejbPU login successful Avertissement: A system exception occurred during an invocation on EJB personService method public void facade.personService.create(classes.personnes) javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean
Code EJB stateless (hellotest) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 public class Main { @EJB private static hellotestRemote hellotest; /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println(hellotest.sayhello()); System.out.println("ça commence"); //System.out.println(hellotest.createNewPerson("BONHOURE", "Bastien")); hellotest.createNewPerson("BONHOURE", "Bastien"); System.out.println("c'est fini"); } }
Code EJB local (personService) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 @Stateless public class hellotest implements hellotestRemote { @EJB private personServiceLocal personService; @Override public String sayhello() { return "exars"; } @Override public void createNewPerson(String nom, String prenom) { personnes person = new personnes(); person.setNom(nom); person.setPrenom(prenom); personService.create(person); } }
Code persistence.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 @Stateless(name="personService") @TransactionManagement(TransactionManagementType.CONTAINER) //@TransactionAttribute(TransactionAttributeType.MANDATORY) public class personService implements personServiceLocal { @PersistenceContext(unitName="test-ejbPU") private EntityManager em; @Override @TransactionAttribute(value=TransactionAttributeType.REQUIRED) public void create(personnes person) { em.persist(person); //System.out.println("la sauce"); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="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="test-ejbPU" transaction-type="JTA"> <provider>oracle.toplink.essentials.PersistenceProvider</provider> <jta-data-source>jdbc/wsdbPool</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> </properties> </persistence-unit> </persistence>
Partager