cavolo ,ho questo problema praticamente ho un entità utente e poi un entità paziente con una relazione onetomany e manytoone,praticamente io vado ad eseguire register...Praticamente io vado a rendere persistenti sia utente che paziente,quindi ora sono in uno stato detached,in seguito faccio paziente.setUtente(u),nella relazione manytoone di paziente ho appunto che devo inserire un utente,quindi inserisco l'utente ed essendo in uno stato attached,il cambiamento dovrebbe essere automatico...mi da il seguente errore: unique constraint (ALLENAVITA.PK_PAZIENTE) violated
non capisco il perchè,visto che il db è vuoto e questo è il primo inserimento dell'utente e paziente,piccolo particolare
@Stateful
@LocalBean
public class RegistrationService implements Serializable {
@PersistenceContext
public EntityManager entityManager;
@Inject
private UserTransaction utx;
public void register(Paziente paziente1,Utente u) throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
System.out.println("Sto per fare il persist");
Set<Paziente> settaggiopaz=new HashSet<Paziente>();
settaggiopaz.add(paziente1);
u.setPazientes(settaggiopaz);
entityManager.persist(u);
entityManager.persist(paziente1);
paziente1.setUtente(u);
}