Bonjour tout le monde, je suis entrain de faire une application en JavaEE avec server glassfish et JSF/facelet.Tout mon programme marche sauf que j'ai un problème sur mon Entity Manager em.remove j'ai une exeption, une belle stack trace :
Comme on peut le voir a la fin de mon message mon entity est dans un état détacher et ne peut pas être remove.J'ai donc essayer de tricher un petit coup en faisant un em.merge() mais rien n'y fais
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 Caused by: javax.ejb.EJBException at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119) at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5017) at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4805) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2004) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955) at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198) at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84) at $Proxy116.removeTicket(Unknown Source) at managed.bean.TicketController.deleteTicket(TicketController.java:180) 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:597) at com.sun.el.parser.AstValue.invoke(AstValue.java:234) at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297) at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) ... 38 more Caused by: java.lang.IllegalArgumentException: Entity must be managed to call remove: suptrac.entity.bean.Ticket[id=602], try merging the detached and try the remove again. at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.performRemove(UnitOfWorkImpl.java:3539)
Voila mon Managed Bean
Voila mon SessionBean :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 public String deleteTicket() { ticketSessionBean.removeTicket(ticket); return "go-to-new"; }
Voila mon EntityBean :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 public void removeTicket(Ticket ticket) { em.merge(ticket); em.remove(ticket); }
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 package suptrac.entity.bean; import java.io.Serializable; import java.util.Date; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Temporal; import suptrac.statuses.priorities.TicketPriority; import suptrac.statuses.priorities.TicketStatus; /** * * @author bush */ @Entity @Table(name="TICKETS") public class Ticket implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String summary; private String description; private TicketPriority priority; private TicketStatus status; @Temporal(javax.persistence.TemporalType.TIMESTAMP) private Date creationDate; @ManyToOne private ProductOwner reporter; @ManyToOne private Developer developer; @OneToMany(cascade=CascadeType.ALL, mappedBy = "ticket") private List<Comment> comments; public List<Comment> getComments() { return comments; } public void setComments(List<Comment> comments) { this.comments = comments; } public Date getCreationDate() { return creationDate; } public void setCreationDate(Date creationDate) { this.creationDate = creationDate; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Developer getDeveloper() { return developer; } public void setDeveloper(Developer developer) { this.developer = developer; } public TicketPriority getPriority() { return priority; } public void setPriority(TicketPriority priority) { this.priority = priority; } public ProductOwner getReporter() { return reporter; } public void setReporter(ProductOwner reporter) { this.reporter = reporter; } public TicketStatus getStatus() { return status; } public void setStatus(TicketStatus status) { this.status = status; } public String getSummary() { return summary; } public void setSummary(String summary) { this.summary = summary; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Ticket)) { return false; } Ticket other = (Ticket) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "suptrac.entity.bean.Ticket[id=" + id + "]"; }
Partager