Erreur "detached entity passed to persist"
Bonjour,
J'ai une erreur :
Citation:
org.hibernate.PersistentObjectException: detached entity passed to persist: fastflow.metier.Workflow
Je souhaite créer un petit moteur WebFlow où chaque workflow est composé de plusieurs activités.
Voici mon code :
Classe Workflow
Code:
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
| @Entity
public class Workflow implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String name;
private String description;
private Boolean publier;
@Temporal(TemporalType.DATE)
private Date creationDate;
@OneToMany(mappedBy="parrentWf")
public List<Activity> activities;
@OneToMany(mappedBy="parrentWf")
public List<WorkflowSession> sessions;
@ManyToOne
public User owner;
@ManyToMany(mappedBy="registeredWorkflows")
public List<User> participants;
public Workflow() {
super();
}
public Workflow(String name, String description, User owner) {
super();
this.name = name;
this.description = description;
this.owner = owner;
this.creationDate = new Date();
}
public Workflow(String name, String description) {
super();
this.name = name;
this.description = description;
this.creationDate = new Date();
}
/*getters and setters */
} |
Classe Activity
Code:
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
| @Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "ACTIVITY_TYPE", length = 3)
public abstract class Activity implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String title;
private String name;
@OneToMany(mappedBy="parrentActivity")
private List<Transition> transition;
@ManyToOne(cascade=CascadeType.ALL)
public Workflow parrentWf;
public Activity() {
super();
}
public Activity(String nom,String titre, Workflow parrentWf) {
super();
this.name = nom;
this.parrentWf = parrentWf;
this.title=titre;
}
/*getters and setters */
} |
Mon EJB Statless
Code:
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
| @Stateless
@TransactionManagement(value=TransactionManagementType.CONTAINER)
@TransactionAttribute(value=TransactionAttributeType.REQUIRED)
public class WorkflowManager implements IWorkflowManager {
@PersistenceContext(name="fastflow_jpa")
EntityManager em;
@Override
public void addWorkflow(Workflow wf) {
em.persist(wf);
}
@Override
public void addActivity(Activity act) {
em.persist(act);
}
@Override
public void addWorkflow(Workflow wf, User owner) {
wf.setOwner(owner);
addWorkflow(wf);
//owner.getWorkflows().add(wf);
}
@Override
public void addActivity(Activity act, Workflow wf) {
act.setParrentWf(wf);
addActivity(act);
//wf.getActivities().add(act);
}
} |
Enfin ma servlet
Code:
1 2 3 4 5
| User u = um.getUserByEmail("email@gmail.com").get(0);
Workflow wf = new Workflow("Work flow 1022", "description wf 1022");
wm.addWorkflow(wf,u);
Activity act = new Implementation("act 1","title act 1",wf);
wm.addActivity(act); // Mon programme plante ici et génère l'exception citée en haut. |
Quand je remplace persist par merge ça marche mais je suis sûr que quelque chose ne va pas et que le problème apparaîtra dans un autre contexte que celui là.
Quelqu'un saurait-il m'indiquer d'où peut venir le problème ?
Merci d'avance pour votre aide.