-->
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.  [ 3 posts ] 
Author Message
 Post subject: 1-1 optional property which is on other table... ideas...
PostPosted: Mon Oct 17, 2005 11:29 am 
Newbie

Joined: Fri Dec 19, 2003 1:31 pm
Posts: 12
Hibernate version: 3.05

Mapping documents:
<hibernate-mapping package="cr.go.ice.gescom.domain">
<class name="Cliente" table="CLIENTE">
<id name="idCliente" type="long" column="IDCLIENTE">
<generator class="sequence">
<param name="sequence">CLIENTE_ID_SEQ</param>
</generator>
</id>
<property name="identificacionCliente" column="IDENTIFICACIONCLIENTE" type="string" not-null="true"/>
</class>
</hibernate-mapping>

<hibernate-mapping package="cr.go.ice.gescom.domain">
<class name="RutaCobro" table="RUTACOBRO">
<id name="idRutaCobro" column="IDRUTACOBRO">
<generator class="sequence">
<param name="sequence">RUTACOBRO_ID_SQ</param>
</generator>
</id>
<property name="numeroApartado" column="NUMEROAPARTADO" type="string" not-null="true"/>
<property name="zonaPostal" column="ZONAPOSTAL" type="string" not-null="true"/>
<property name="rutaCobro" column="RUTACOBRO" type="integer" not-null="true"/>
<one-to-one name="cliente" foreign-key="IDCLIENTE" class="Cliente"/>
</class>
</hibernate-mapping>


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

There is an object called "Cliente" which, in some cases, may had a "RutaCobro" object. I had defined this like a many-to-one relationship on the data base, for example:
- table Cliente:
- idCliente PK
- table RutaCobro:
- idRutaCobro PK
- idCliente FK

I now that that is not the best option... and what I really want to do is this:
- table Cliente:
- idCliente PK
- table RutaCobro
- idCliente PK, FK

So I now that there is only one "RutaCobro" for every "Cliente" that needs it. I don't had find any solution to this in hibernate, maybe I just couldn't undestand how to apply a one-to-one relationship in a object level.

there is anyway to do what I need to do? Can I make the following:
Code:
cliente.getRutaCobro()
and hopefully that does not give me a nullPointerException on those "Cliente" that does not has that property.

my case is clear somehow?

thanks.

jorge f.

_________________
jorge fdz
<< cartago, cr >>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 11:42 am 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
I think what you are trying to do is explained here: http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#assoc-bidirectional-121.

Look at the part about
Quote:
bidirectional one-to-one association on a primary key

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 11:53 am 
Newbie

Joined: Fri Dec 19, 2003 1:31 pm
Posts: 12
yeap, I already try to use this one, but I wasn't sure if it really applies in my case, I will implement it and give it a try...

I will post what happend to this...

thanks....

_________________
jorge fdz
<< cartago, cr >>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.