-->
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: <one-to-one> mapping
PostPosted: Wed Mar 08, 2006 12:28 am 
Newbie

Joined: Thu Feb 23, 2006 5:54 am
Posts: 12
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Hi,I am new to this technology.I faced one problem to map 2 tables.
I want map the id(PK) of usermetrics table and userId(it is not pk) of usermetricsdetails table. In usermetricsdetails table id is primary key.
I need to map with userid. I have one-to-one relation is there between 2 tables.Please give solution asap.

Thanks
Mohana Priya


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 5:40 am 
Newbie

Joined: Tue Mar 07, 2006 3:15 pm
Posts: 17
You want a one-to-one relationship without a foreign key? How are hibernate going to be able to traverse such a relationship in the db?

Make it a foreign key and follow the information in this chapter of the manual

Chapter 5 Basic O/R Mapping

Alternatively you can use a primary key relationship; that is the two rows in the two different tables share the same primary key value. It is described in the link above..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 6:18 am 
Newbie

Joined: Fri Feb 24, 2006 9:15 am
Posts: 17
Hello,

I hope you don't mind me barging into this thread, but I you mentioned that primary keys could be used to link a one-to-one mapping, I have a problem trying to achieve that with a composite id. Could you shine a light on it?

I have 2 classes/tables, each with the following composite key and one-to-one definition:
<composite-id name="id"
class="es.facturacion.om.PedidoHistoricoId">
<meta attribute="implement-equals" />
<key-property name="cliente" type="string">
<meta attribute="use-in-equals" >true</meta>
<column name="cliente" length="12" />
</key-property>
<key-property name="fecha" type="java.lang.Integer">
<meta attribute="use-in-equals" >true</meta>
<column name="fecha" />
</key-property>
<key-property name="serie" type="string">
<meta attribute="use-in-equals" >true</meta>
<column name="serie" length="2" />
</key-property>
<key-property name="numero" type="java.lang.Integer">
<meta attribute="use-in-equals" >true</meta>
<column name="numero" />
</key-property>
</composite-id>
<one-to-one name="PedidoDia" class="es.facturacion.om.PedidoDia"/>

(So the map to the same class and have equals and hashCode defined).

Now I have the following test case:
PedidoDiaId commonId = new PedidoDiaId ("00023",new Integer(20060223),"AA",new Integer(1));
pedido [0] = new PedidoDiaDetalle (commonId);
PedidoDia pedidoDia = new PedidoDia (commonId);
// both saved here

And then:
Criteria criteria = session.createCriteria(PedidoDiaDetalle.class);
criteria.add(Restrictions.idEq(commonId));
List results = criteria.list();
AssertJUnit.assertTrue(results!=null);
PedidoDiaDetalle pdd = (PedidoDiaDetalle) results.get(0);
AssertJUnit.assertTrue(pdd!=null);
PedidoDia pd = pdd.getPedidoDia();
AssertJUnit.assertTrue(pd!=null);

This fails, it returns a null for pd.

Am I missing something here?

Regards, Bo


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 7:15 am 
Newbie

Joined: Tue Mar 07, 2006 3:15 pm
Posts: 17
Sorry, never used this for a composite id, only for single Integer ids.


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.