Bonjour
J'ai récupéré un projet que je migre de MYSQL vers POSTGRES et sous JBOSS EAP6 6.4.22
Lorsque dans ma form je cherche à inserer un nouvel enregistrement
* je n'ai aucun message d'erreur
* et l'insert n'est pas effectué dans POSTGRES
* mais la sequence qui sert de clef primaire est bien incrementée !!
j'utilise org.eclipse.persistence.jpa.PersistenceProvider et POSTGRES12
Où est mon erreur ? Merci d'avance
standalone.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
19
20
21
22
23
24
25
26
27
28
29 private static final Log logger = LogFactory.getLog(AuthorService.class); @PersistenceContext(unitName = "bookstorePersistenceUnit") private EntityManager em; @Override protected EntityManager getEntityManager() { return em; } public AuthorService() { super(Author.class); } @Override public void create(Author author) { Set<Book> authoredBooks = author.getAuthoredBooks(); if (authoredBooks != null && authoredBooks.size() > 0) { for (Book book : authoredBooks) { if (book.getAuthors() == null) { book.setAuthors(new HashSet<Author>()); } book.getAuthors().add(author); em.merge(book); } } em.persist(author); logger.info("apres em.persist(author); persist de Author"); }
Code XML : 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 <subsystem xmlns="urn:jboss:domain:transactions:1.5"> <core-environment> <process-id> <uuid/> </process-id> </core-environment> <recovery-environment socket-binding="txn-recovery-environment" status-socket-binding="txn-status-manager"/> <coordinator-environment default-timeout="300"/> </subsystem> <datasource jta="true" jndi-name="java:jboss/datasources/book" pool-name="book" enabled="true" use-java-context="true" use-ccm="false"> <connection-url>jdbc:postgresql://localhost:5432/book</connection-url> <driver>postgres</driver> <security> <user-name>postgres</user-name> <password>admin</password> </security> </datasource>
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 @Entity @Table(name = "AUTHORS") public class Author implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue( strategy = GenerationType.AUTO, generator = "authors_seq_gen3" ) @SequenceGenerator( name="authors_seq_gen3", sequenceName="AUTHORS_SEQ_GEN3", initialValue=5, allocationSize=1 ) //create sequence AUTHORS_SEQ_GEN3 START WITH 5 INCREMENT BY 1; //select currval('AUTHORS_SEQ_GEN3'); select nextval('AUTHORS_SEQ_GEN3'); @Column(name = "id") private Long id; @Size(min = 1, max = 50) @NotNull private String firstName; @Size(min = 1, max = 50) @NotNull private String lastName; @ManyToMany(mappedBy = "authors", fetch = FetchType.EAGER) private Set<Book> authoredBooks; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public Set<Book> getAuthoredBooks() { return authoredBooks; } public void setAuthoredBooks(Set<Book> authoredBooks) { this.authoredBooks = authoredBooks; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Author other = (Author) obj; if (id == null) { if (other.id != null) { return false; } } else if (!id.equals(other.id)) { return false; } return true; } @Override public String toString() { return "Author{" + "firstName=" + firstName + ", lastName=" + lastName + '}'; } }
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.jee.tutorial.bookstore.ejb; import java.util.List; import javax.persistence.EntityManager; /** * * @author ikolev */ @SuppressWarnings({"rawtypes", "unchecked"}) public abstract class JPAService<T> { private Class<T> entityClass; public JPAService(Class<T> entityClass) { this.entityClass = entityClass; } protected abstract EntityManager getEntityManager(); public void create(T entity) { getEntityManager().persist(entity); } public void edit(T entity) { getEntityManager().merge(entity); } public void remove(T entity) { getEntityManager().remove(entity); } public T find(Object id) { return getEntityManager().find(entityClass, id); } public List<T> findAll() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return getEntityManager().createQuery(cq).getResultList(); } public List<T> findRange(int[] range) { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); javax.persistence.Query q = getEntityManager().createQuery(cq); q.setMaxResults(range[1] - range[0]); q.setFirstResult(range[0]); return q.getResultList(); } public int count() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); javax.persistence.criteria.Root<T> rt = cq.from(entityClass); cq.select(getEntityManager().getCriteriaBuilder().count(rt)); javax.persistence.Query q = getEntityManager().createQuery(cq); return ((Long) q.getSingleResult()).intValue(); } }
persistence.xml
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.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_2_0.xsd"> <persistence-unit name="bookstorePersistenceUnit" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>java:jboss/datasources/book</jta-data-source> <class>com.jee.tutorial.bookstore.jpa.Author</class> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="eclipselink.logging.level.sql" value="FINE" /> <property name="eclipselink.logging.parameters" value="true" /> </properties> </persistence-unit> </persistence>
Dans les modules de JBOSS
Code XML : 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
24 <module xmlns="urn:jboss:module:1.1" name="org.eclipse.persistence"> <resources> <resource-root path="eclipselink-2.7.7.jar"> <resource-root path="javax.persistence-api-2.2.jar"> <filter> <exclude path="javax/**" /> </filter> </resource-root> </resources> <dependencies> <module name="javax.api"/> <module name="javax.persistence.api"/> <module name="javax.transaction.api"/> <module name="javax.validation.api"/> <module name="javax.xml.bind.api"/> <module name="org.antlr"/> <module name="org.apache.commons.collections"/> <module name="org.dom4j"/> <module name="org.javassist"/> <module name="org.jboss.logging"/> <module name="org.postgresql"/> </dependencies> </module>
Je pense que mon soucis provient de la gestion ou non gestion des transactions par mon JBOSS EAP6
Partager