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.  [ 4 posts ] 
Author Message
 Post subject: Null-Value in Foreign-Key
PostPosted: Mon Dec 18, 2006 8:02 am 
Newbie

Joined: Thu Feb 16, 2006 4:16 am
Posts: 17
Location: Austria
Hallo Hibernate-User,

ich habe bezüglich der Annotationen in Hibernate einige Fragen. Zurzeit verwende ich bei einem Szenario zwei Tabellen, die erste Tabelle ist z.B. eine Parent-Tabelle. Die Verbindung zur Tabelle Children ist über eine 1:n-Beziehung festgelegt.

Es kann jetzt aber sein, dass dieses n = 0 ist. Wie kann ich das in Hibernate abbilden? Beim Mapping wird eine ManyToOne-Annotation verwendet. Genau das führt dann zu Problemen, wenn in der DB in der Spalte children_id <null> hinterlegt ist.

Tabelle: PARENT(id, text, children_id nullable)
Tabelle: CHILDREN(id, text)
Constraint: PARENT.children_id references CHILDREN(id)

Gibt es dazu eine Lösung, wie man bei möglichen NULL-Werten zwar alle PARENTs bekommt aber beim gefetchten Objekt ein null-Wert steht?

Hibernate version:
Hibernate 3.2.0CR2

Database-Version:
Ingres 9.0.4

Query:
FROM Parent par INNER JOIN FETCH par.children

Ich hoffe ihr könnt mir dabei weiterhelfen.

Besten Dank im Voraus und lG,
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 11:52 am 
Newbie

Joined: Tue Feb 14, 2006 5:13 am
Posts: 18
hast du es schon mal mit einem outer join versucht:
Code:
FROM Parent par LEFT OUTER JOIN FETCH par.children


gruss,
andi


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 12:22 pm 
Newbie

Joined: Thu Feb 16, 2006 4:16 am
Posts: 17
Location: Austria
Ein LEFT JOIN FETCH hat geholfen.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 5:07 pm 
Newbie

Joined: Tue Feb 14, 2006 5:13 am
Posts: 18
hm, ich dachte immer LEFT JOIN ist nur eine abkürzung für LEFT OUTER JOIN, so wie JOIN eine abkürzung für INNER JOIN ist. sicher dass LEFT OUTER JOIN nicht ging?


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

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.