Bonjour,
Je rencontre un problème de persistance en JPA sous Glassfish :
javax.persistence.TransactionRequiredException
log Glassfish :
NFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Current wizard step:personal
INFO: Next step:identifiant
INFO: Current wizard step:identifiant
INFO: Next step:address
INFO: Current wizard step:address
INFO: Next step:contact
INFO: Current wizard step:contact
INFO: Next step:confirm
WARNING: PWC4011: Unable to set request character encoding to utf-8 from context /Zeitjager, because request parameters have already been read, or ServletRequest.getReader() has already been called
INFO: EXCEPTION CLASS NAME: javax.persistence.TransactionRequiredException
SEVERE: Réception de 'java.lang.NullPointerException' lors de l'invocation du listener d'action '#{adherentEntryEJB.save}' du composant 'j_idt84'
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
89
90
91
92
93
94 AdherentEntryEJB : package com.zeitjager.ejb; import java.util.logging.Level; import java.util.logging.Logger; import javax.ejb.Stateless; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.primefaces.event.FlowEvent; import com.zeitjager.entity.AdherentEntry; @ManagedBean @SessionScoped @Stateless public class AdherentEntryEJB { @PersistenceContext(unitName = "defaultPersistenceUnit") private EntityManager em; private AdherentEntry user = new AdherentEntry(); private boolean skip; private static Logger logger = Logger.getLogger(AdherentEntryEJB.class.getName()); public AdherentEntry getUser() { return user; } public void setUser(AdherentEntry user) { this.user = user; } public void save(ActionEvent actionEvent) { FacesMessage msg = new FacesMessage("Successful", "Welcome :" + user.getFirstname()); FacesContext.getCurrentInstance().addMessage(null, msg); //Persist user this.saveAdherentEntry(user); } public boolean isSkip() { return skip; } public void setSkip(boolean skip) { this.skip = skip; } public String onFlowProcess(FlowEvent event) { logger.info("Current wizard step:" + event.getOldStep()); logger.info("Next step:" + event.getNewStep()); if(skip) { skip = false; //reset in case user goes back return "confirm"; } else { return event.getNewStep(); } } public AdherentEntry saveAdherentEntry(AdherentEntry adherentEntry) { try { em.persist(adherentEntry); } catch (javax.persistence.PersistenceException ex) { System.out.println("EXCEPTION CLASS NAME: " + ex.getClass().getName().toString()); System.out.println("THROWABLE CLASS NAME: " + ex.getCause().getClass().getName().toString()); Throwable th = ex.getCause(); System.out.println("THROWABLE INFO: " + th.getCause().toString()); Logger.getLogger(AdherentEntryEJB.class .getName()).log(Level.INFO, "adherentEntry Controller " + "persistence exception " + "EXCEPTION STRING: {0}", ex.toString()); Logger.getLogger(AdherentEntryEJB.class .getName()).log(Level.INFO, "adherentEntry Controller " + "persistence exception " + "THROWABLE MESSAGE: {0}", th.getMessage()); Logger.getLogger(AdherentEntryEJB.class .getName()).log(Level.INFO, "AdherentEntryEJB Controller " + "persistence exceptions " + "THROWABLE STRING: {0}", th.toString()); } return saveAdherentEntry(adherentEntry); } }
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 AdherentEntryBean : package com.zeitjager.controller; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import com.zeitjager.ejb.AdherentEntryEJB; import com.zeitjager.entity.AdherentEntry; @Named(value = "adherentEntryBean") @RequestScoped public class AdherentEntryBean { @Inject private AdherentEntryEJB adherentEntryEJB; private AdherentEntry adherentEntry = new AdherentEntry(); /** * @return the adherentEntry */ public AdherentEntry getAdherentEntry() { return adherentEntry; } public String saveBlogEntry() { adherentEntryEJB.saveAdherentEntry(adherentEntry); return "success"; } /** * @param adherent * the adherent to set */ public void setAdherentEntry(AdherentEntry adherentEntry) { this.adherentEntry = adherentEntry; } }
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171 AdherentEntry : package com.zeitjager.entity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import org.hibernate.validator.Min; import org.hibernate.validator.NotEmpty; import org.hibernate.validator.Size; import javax.persistence.TableGenerator; import javax.persistence.SequenceGenerator; import javax.validation.constraints.Pattern; @Entity @TableGenerator(name = "Adherent", table = "adherententity") @SequenceGenerator(name = "Adherent_sequence") public class AdherentEntry { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @Size(min = 3, max = 20) @Column(name = "Identifiant", nullable = false, columnDefinition = "char(20)") private String identifiant; @Size(min = 3, max = 20) @Column(name = "Firstname", nullable = false, columnDefinition = "char(20)") private String firstname; @Size(min = 3, max = 20) @Column(name = "Lastname", nullable = false, columnDefinition = "char(20)") private String lastname; @Min(18) @Column(name = "Age", nullable = false, columnDefinition = "int(2)") private String age; @Size(min = 3, max = 20) @Column(name = "Password", nullable = false, columnDefinition = "char(20)") @NotEmpty private String password; @Size(min = 3, max = 80) @Column(name = "Street", nullable = false, columnDefinition = "char(20)") private String street; @Pattern(regexp = "[0-9]{5}") @Column(name = "PostalCode", nullable = false, columnDefinition = "int(5)") private String postalCode; @Size(min = 3, max = 20) @Column(name = "City", nullable = false, columnDefinition = "char(20)") private String city; @Size(max = 30) @Column(name = "Email", nullable = false, columnDefinition = "char(20)") private String email; @Pattern(regexp = "[0-9]{10}") @Column(name = "Phone", nullable = false, columnDefinition = "char(10)") private String phone; @Size(min = 10, max = 200) @Column(name = "Info", nullable = false, columnDefinition = "char(200)") private String info; public long getId() { return id; } public void setIdentifiant(String identifiant) { this.identifiant = identifiant; } public String getIdentifiant() { return identifiant; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getFirstname() { return firstname; } public void setLastname(String lastname) { this.lastname = lastname; } public String getLastname() { return lastname; } public void setAge(String age) { this.age = age; } public String getAge() { return age; } public void setPassword(String password) { this.password = password; } public String getPassword() { return password; } public void setStreet(String street) { this.street = street; } public String getStreet() { return street; } public void setPostalCode(String postalCode) { this.postalCode = postalCode; } public String getPostalCode() { return postalCode; } public void setCity(String city) { this.city = city; } public String getCity() { return city; } public void setEmail(String email) { this.email = email; } public String getEmail() { return email; } public void setPhone(String phone) { this.phone = phone; } public String getPhone() { return phone; } public void setInfo(String info) { this.info = info; } public String getInfo() { return info; } /** * @param id * the id to set */ public void setId(long id) { this.id = id; } }persistence:
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196 Adherent.xhtml : <?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core"> <h:head> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> <title>Zeitjäger</title> <link rel="stylesheet" type="text/css" href="css/style.css" /> <style type="text/css"> .ui-widget,.ui-widget .ui-widget { font-size: 100% !important; } </style> </h:head> <ui:composition template="/Decorator.xhtml"> <ui:define name="title"> <h:outputText value="#{msg.listTitle}" /> </ui:define> <ui:define name="heading"> <h:outputText value="#{msg.listHeading}" /> </ui:define> <ui:define name="body"> <h:form> <p:growl id="growl" sticky="true" showDetail="true" /> <p:wizard widgetVar="wiz" flowListener="#{adherentEntryEJB.onFlowProcess}"> <p:tab id="personal" title="#{msg.personnel}"> <p:panel header="#{msg.information}"> <h:messages errorClass="error" /> <h:panelGrid columns="2" columnClasses="label, value" styleClass="grid"> <h:outputText value="#{msg.prenom}" /> <p:inputText required="true" label="Firstname" value="#{adherentEntryEJB.user.firstname}" /> <h:outputText value="#{msg.nom}" /> <p:inputText required="true" label="Lastname" value="#{adherentEntryEJB.user.lastname}" /> <h:outputText value="#{msg.age}" /> <p:inputText value="#{adherentEntryEJB.user.age}" /> <h:outputText value="#{msg.skiplast}" /> <h:selectBooleanCheckbox value="#{adherentEntryEJB.skip}" /> </h:panelGrid> </p:panel> </p:tab> <p:tab id="identifiant" title="#{msg.identifiant}"> <p:panel header="Identifiant Details"> <h:messages errorClass="error" /> <h:panelGrid columns="2" columnClasses="label, value"> <h:outputText value="#{msg.identifiantsaisie}" /> <p:inputText value="#{adherentEntryEJB.user.identifiant}" /> <h:outputText value="#{msg.password}" id="Password" /> <p:inputText value="#{adherentEntryEJB.user.password}" /> <h:outputText value="#{msg.skiplast}" /> <h:selectBooleanCheckbox value="#{adherentEntryEJB.skip}" /> <p:tooltip for="Password" value="#{msg.messageinfo}" showEffect="fade" hideEffect="fade" /> </h:panelGrid> </p:panel> </p:tab> <p:tab id="address" title="#{msg.Adresse}"> <p:panel header="#{msg.Adressedetail}"> <h:messages errorClass="error" /> <h:panelGrid columns="2" columnClasses="label, value"> <h:outputText value="#{msg.rue}" /> <p:inputText value="#{adherentEntryEJB.user.street}" /> <h:outputText value="#{msg.codepostal}" id="postalCode" /> <p:inputText value="#{adherentEntryEJB.user.postalCode}" /> <h:outputText value="#{msg.ville}" /> <p:inputText value="#{adherentEntryEJB.user.city}" /> <h:outputText value="#{msg.skiplast}" /> <h:selectBooleanCheckbox value="#{adherentEntryEJB.skip}" /> <p:tooltip for="postalCode" value="#{msg.messagepostalCode}" showEffect="fade" hideEffect="fade" /> </h:panelGrid> </p:panel> </p:tab> <p:tab id="contact" title="#{msg.contact}"> <p:panel header="#{msg.contactinformation}"> <h:messages errorClass="error" /> <h:panelGrid columns="2" columnClasses="label, value"> <h:outputText value="#{msg.email}" /> <p:inputText id="email" required="true" label="email" size="40" requiredMessage="#{msg.saisieemail}" validatorMessage="#{msg.invalidsaisieemail}" value="#{adherentEntryEJB.user.email}"> <f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" /> </p:inputText> <p:watermark for="email" value="#{msg.watermarkemail}" /> <p:message for="email" /> <h:outputText value="#{msg.phone}" /> <p:inputText value="#{adherentEntryEJB.user.phone}" /> <h:outputText value="#{msg.informationcomplementaire}" /> <p:inputText value="#{adherentEntryEJB.user.info}" size="60" /> </h:panelGrid> </p:panel> </p:tab> <p:tab id="confirm" title="#{msg.confirmation}"> <p:panel header="#{msg.confirmation}"> <h:panelGrid id="confirmation" columns="2"> <h:outputText value="#{msg.prenom}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.firstname}" /> <h:outputText value="#{msg.nom}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.lastname}" /> <h:outputText value="#{msg.age}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.age}" /> <h:outputText value="#{msg.identifiantsaisie}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.identifiant}" /> <h:outputText value="#{msg.password}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.password}" /> <h:outputText value="#{msg.rue}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.street}" /> <h:outputText value="#{msg.codepostal}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.postalCode}" /> <h:outputText value="#{msg.ville}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.city}" /> <h:outputText value="#{msg.email}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.email}" /> <h:outputText value="#{msg.phone}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.phone}" /> <h:outputText value="#{msg.informationcomplementaire}" /> <h:outputText styleClass="outputLabel" value="#{adherentEntryEJB.user.info}" /> <h:commandButton value="#{msg.validation}" actionListener="#{adherentEntryEJB.save}"/> </h:panelGrid> </p:panel> </p:tab> </p:wizard> </h:form> </ui:define> </ui:composition> </html>
Probléme :
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 <?xml version="1.0" ?> <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="defaultPersistenceUnit" transaction-type="JTA"> <description>Zeitjager -Time's Hunter - Chasseur de temps</description> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>zeitjager</jta-data-source> <class>com.zeitjager.entity.AdherentEntry</class> <class>com.zeitjager.entity.DocumentEntry</class> <class>com.zeitjager.entity.EpavetrouveEntry</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/> <property name="hibernate.hbm2ddl.auto" value="create"/> <property name="hibernate.show.sql" value="true" /> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.username" value="zeitjager"/> <property name="hibernate.connection.password" value="zeitjager"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/zeitjager"/> <property name="hibernate.default_catalog" value="Zeitjager"/> </properties> </persistence-unit> </persistence>
Au moment d'invoquer adherentEntryEJB.save je prends une exception INFO: EXCEPTION CLASS NAME: javax.persistence.TransactionRequiredException
je ne vois pas pourquoi , si vous pouvez m'aider merci beaucoup à vous
Partager