Hi Leute,
ich bastele seit zwei Tagen an einem kleinen ELB 3.0-Projekt und finde die Ursache für das Problem nicht. Ich habe eine Contact-Bean, die mehrere Details enthalten soll (Detail-Bean). Die Beans sehen wie folgt aus:
Das Anlegen eines Contacts sowie entsprechender Details und auch das Löschen der Details funktionieren einwandfrei. Allerdings ist es nicht möglich, einen Contact zu löschen, sobald dieser Details enthält. Meine Session-Bean sieht so aus:
Beim Versuch, einen Contact zu löschen, der mind. 1 Detail enthält, erscheint folgende Meldung:
Caused by: engine.services.ts.exceptions.BaseRollbackException: Exception in beforeCompletition of ( SAP J2EE Engine JTA Transaction : [034ffffffc2ffffffd6006ffffffd2] ).
Caused by: javax.persistence.PersistenceException: SQLException while removing entity {Contact(id=108)}.
Caused by: dbtech.jdbc.exceptions.DatabaseException: [350]: Referential integrity violated:contact,ADMIN,DETAIL
Ich sitze seit zwei Tagen an der Sache, hab auch eine ungefähre Ahnung, woran es liegt, aber keine Idee, was ich dagegen tun kann
Danke, Stefan
ich bastele seit zwei Tagen an einem kleinen ELB 3.0-Projekt und finde die Ursache für das Problem nicht. Ich habe eine Contact-Bean, die mehrere Details enthalten soll (Detail-Bean). Die Beans sehen wie folgt aus:
Code:
@Entity
public class Contact implements Serializable {
private int id;
private Set<Detail> detailsCollection;
public Contact() {
this.detailsCollection = null;
}
@Id
@GeneratedValue
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER, mappedBy = "contact")
public Set<Detail> getDetailsCollection() {
return this.detailsCollection;
}
public void setDetailsCollection(Set<Detail> detailsCollection) {
this.detailsCollection = detailsCollection;
}
}
Code:
@Entity
public class Detail implements Serializable {
private int id;
private Contact contact;
public Detail() {
this.contact = null;
}
public Detail(Contact contact) {
this.contact = contact;
}
@Id
@GeneratedValuevalueColumnName = "MAX_ID")
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@ManyToOne
@JoinColumn(name = "CONTACT")
public Contact getContact() {
return this.contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
}
Das Anlegen eines Contacts sowie entsprechender Details und auch das Löschen der Details funktionieren einwandfrei. Allerdings ist es nicht möglich, einen Contact zu löschen, sobald dieser Details enthält. Meine Session-Bean sieht so aus:
Code:
public void createContact() {
Contact contact = new Contact();
em.persist(contact);
}
public void removeContact(int contactID) {
Contact contact = em.find(Contact.class, Integer.valueOf(contactID));
em.remove(contact);
}
@SuppressWarnings("unchecked")
public Collection<Contact> getContacts() {
return em.createQuery("select c from Contact c").getResultList();
}
public void addDetail(int contactID) {
Contact contact = em.find(Contact.class, Integer.valueOf(contactID));
contact.getDetailsCollection().add(new Detail(contact));
em.merge(contact);
}
public void removeDetail(int detailID) {
Detail detail = em.find(Detail.class, Integer.valueOf(detailID));
Contact contact = detail.getContact();
contact.getDetailsCollection().remove(detail);
em.remove(detail);
}
@SuppressWarnings("unchecked")
public Collection<Detail> getDetails(int contactID) {
Contact contact = em.find(Contact.class, Integer.valueOf(contactID));
return contact.getDetailsCollection();
}
Beim Versuch, einen Contact zu löschen, der mind. 1 Detail enthält, erscheint folgende Meldung:
Caused by: engine.services.ts.exceptions.BaseRollbackException: Exception in beforeCompletition of ( SAP J2EE Engine JTA Transaction : [034ffffffc2ffffffd6006ffffffd2] ).
Caused by: javax.persistence.PersistenceException: SQLException while removing entity {Contact(id=108)}.
Caused by: dbtech.jdbc.exceptions.DatabaseException: [350]: Referential integrity violated:contact,ADMIN,DETAIL
Ich sitze seit zwei Tagen an der Sache, hab auch eine ungefähre Ahnung, woran es liegt, aber keine Idee, was ich dagegen tun kann
Danke, Stefan