-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: hibernate nicht konsistent mit DB
PostPosted: Tue Dec 13, 2005 5:03 pm 
Newbie

Joined: Tue Dec 13, 2005 4:43 pm
Posts: 1
Hallo zusammen,

folgender Programmablauf:

Query query = s.createQuery("from azn.logik.Institution where id=30");
List list = query.list();
Iterator iter = list.iterator();

Institution i = (Institution) iter.next();
s.delete(i);
s.flush();

query = s.createQuery("from azn.logik.Person where id=4");
list = query.list();
iter = list.iterator();

Person p9 = (Person) iter.next();

Zum Verständnis: Eine Person gehört einer Institution an. Hier gehört die Person mit ID 4 der Institution mit ID 30 an. Dies steht auch alles so in der DB. Trotz s.delete und s.flush wird der Fremdschlüssel in der Person nicht auf Null gesetzt. Ich habe schon alle möglichen Einstellungen versucht.
Ein commit habe ich absichtlich weggelassen, sollte ja auch so gehen.
Das Problem ist mir auch klar, hibernate puffert zwischen und lies nicht aus der Datenbank, denn dann wüßte es, das es die Institution und den Fremdschlüssel nicht mehr gibt. Ach ja, ich habe übrigens folgenden Fremdschlüssel in der Datenbank benutzt:

ALTER TABLE person
ADD CONSTRAINT person_fk_Institution_1 FOREIGN KEY (institution_Id)
REFERENCES Institution (id)
ON delete set null;



Hibernate version:3.1

Mapping documents:
Quote:
<hibernate-mapping>
<class name="azn.logik.Institution" table="INSTITUTION">
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">SEQUENCE_INSTITUTION</param>
</generator>
</id>
<property name="name" column="NAME" length="30" not-null="true"></property>
<set name="gruppen" inverse="true">
<key column="INSTITUTION_ID"></key>
<one-to-many class="azn.logik.Gruppe"></one-to-many>
</set>
<set name="unterinstitutionen" inverse="true">
<key column="OBERINSTITUTION_ID"></key>
<one-to-many class="azn.logik.Institution"></one-to-many>
</set>
<set name="mitglieder" inverse="true">
<key column="INSTITUTION_ID" not-null="false"></key>
<one-to-many class="azn.logik.Person"></one-to-many>
</set>
<many-to-one name="oberinstitution" column="OBERINSTITUTION_ID"></many-to-one>
</class>

Quote:
<hibernate-mapping>
<class name="azn.logik.Person" table="PERSON">
<id name="id" column="ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">SEQUENCE_PERSON</param>
</generator>
</id>
<property name="vorname" column="VORNAME" length="30"></property>
<property name="name" column="NAME" length="30"></property>
<property name="login" column="LOGIN" length="30"></property>
<property name="password" column="PASSWORD" length="30"></property>
<property name="personalnummer" column="PERSONALNUMMER" length="30"></property>
<many-to-one name="gruppe" column="GRUPPE_ID"></many-to-one>
<many-to-one name="institution" column="INSTITUTION_ID" not-null="false" cascade="evict"></many-to-one>
<set name="rollen" inverse="true" cascade="all">
<key column="PERSON_ID" not-null="true" on-delete="cascade"></key>
<one-to-many class="azn.logik.Rolle"></one-to-many>
</set>
</class>


Name and version of the database you are using:
Oracle 9i EE 9.2.0.4


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.