ERLEDIGT
NEIN
NEIN
ANTWORTEN
2
2
ZUGRIFFE
3346
3346
EMPFEHLEN
-
24.10.07 10:43 #1
Hallo!
Ich habe 3 Klassen (Domain-Model) mittels Hibernate realisiert. Es funktioniert alles tadellos, aber ich habe immer ein Auge darauf welche SQL-Statements Hibernate erzeugt. Jetzt habe ich eine Situation wo es nicht verstehe.
Klasse: Person
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14
@Entity public class Person extends PersistentObjectAbstract { ... @Column(length=100, unique=false, nullable=true) private String firstName = null; @Column(length=100, unique=false, nullable=true) private String lastName = null; @OneToMany(fetch=FetchType.LAZY) @JoinColumn(name="personId") @IndexColumn(name="listPos") @Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN}) private List<Communication> communications = new ArrayList<Communication>(); ...
Klasse: Organization
Code :1 2 3 4 5 6 7 8 9 10 11 12
@Entity public class Organization extends PersistentObjectAbstract { ... @Column(length=200, unique=false, nullable=false) private String longName = null; @OneToMany(fetch=FetchType.LAZY) @JoinColumn(name="organizationId") @IndexColumn(name="listPos") @Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN}) private List<Communication> communications = new ArrayList<Communication>(); ...
Klasse: Communication
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
@Entity public class Communication extends PersistentObjectAbstract { ... @Column(nullable=true) private int listPos = 0; @Column(length=100, unique=false, nullable=true) private String label = null; @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="personId", insertable=false, updatable=false, nullable=true) private Person person = null; @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="organizationId", insertable=false, updatable=false, nullable=true) private Organization organization = null; ...
Navigation erfolgt über Person -> Communication bzw. Organization -> Communication
Wenn ich nun eine Person lösche macht Hibernate folgendes:
Code :1 2 3 4
Hibernate: update Communication set personId=null, listPos=null where personId=? Hibernate: delete from Communication where id=? and version=? Hibernate: delete from Communication where id=? and version=? Hibernate: delete from Person where id=? and version=?
Erwarten würde ich aber (weil performanter):
Code :1 2
Hibernate: delete from Communication where personid=? Hibernate: delete from Person where id=? and version=?
Ist das so? Oder habe ich einen Fehler in meinem Mapping?
Marco
-
24.10.07 14:55 #2
Ich dürfte wirklich einen Fehler in meinem Mapping haben.
Wenn ich folgendes mache
Code :1 2 3
Person person = (Person) session.load // Person laden person.getCommunications().remove(0); session.update(person);
erhalte ich
Code :1
org.hibernate.exception.ConstraintViolationException: could not delete collection rows: [at.brisk.jazz.domain.Person.communications
Somit bin ich wieder am Anfang
Hat jemand einen Tipp für mich?
Marco
-
14.08.08 12:53 #3
- Registriert seit
- May 2004
- Beiträge
- 32
Hi,
hab dasselbe Problem, Warum Updated Hibernate, wenn es eigentlich löschen soll?
Wurde das Problem bisweilen schon gelöst?
Ähnliche Themen
-
Hibernate: Laden von bidirektionalen Beziehungen erzeugt mehrere SELECT Anweisungen?
Von DarthShader im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 4Letzter Beitrag: 10.11.09, 10:12 -
Problem mit Hibernate und M:N Beziehungen
Von LightBear im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 0Letzter Beitrag: 07.03.08, 09:47 -
Hibernate: CascadeType.ALL bei N:M Beziehungen? Ich bin verwirrt!
Von DarthShader im Forum JavaAntworten: 0Letzter Beitrag: 29.10.07, 12:50 -
Hibernate-Mapping
Von splitshade im Forum JavaAntworten: 0Letzter Beitrag: 24.09.07, 14:03 -
[hibernate] one-to-many mapping Problem
Von wSam im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 0Letzter Beitrag: 23.06.06, 11:39





Zitieren
Login





