-->
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: How to setup simple one-to-one primary key relationship
PostPosted: Mon Feb 02, 2004 3:33 pm 
Beginner
Beginner

Joined: Thu Nov 20, 2003 1:30 pm
Posts: 27
Currently, I do not have a relationship setup. I just use a Long, but I want to change it to use a relationship. The documentation is a little foggy as to what is needed and where it goes when a one-to-one relationship is the primary key.

Here is what I currently have, the commented part is what I've been trying to get the relationship working. I get the error 'param named "property" is required for foreign id generation strategy' though. Any help is appreciated, thanks.

Code:
<class name="com.lsr.eclipse.framework.core.model.PanelRedeemAddress" table="panel_redeem_address">
<id column="panel_id" name="id" type="java.lang.Long">
<generator class="assigned"/>
</id>

<!--
<id column="panel_id" name="panel" type="com.lsr.eclipse.framework.core.model.Panel">
<generator class="foreign"/>
</id>
<one-to-one name="panel" class="com.lsr.eclipse.framework.core.model.Panel" constrained="true"/>
-->

<property column="street1" length="50" name="street1" not-null="true" type="java.lang.String"/>
<property column="street2" length="50" name="street2" type="java.lang.String"/>
<property column="city" length="25" name="city" not-null="true" type="java.lang.String"/>
<property column="state" length="4" name="state" not-null="true" type="java.lang.String"/>
<property column="zipcode" length="15" name="zipcode" not-null="true" type="java.lang.String"/>
<property column="phone" length="25" name="phone" type="java.lang.String"/>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 3:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
type="com.lsr.eclipse.framework.core.model.Panel" in the id property is crap, stick to long here.

Use Foreign id generation, and name the id property of your referenced class in the generator tag.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 4:04 pm 
Beginner
Beginner

Joined: Thu Nov 20, 2003 1:30 pm
Posts: 27
Great, thanks for the quick reply! I have it working, one more question (I'm getting greedy and curious) Is it possible to use the reference to load the object, instead of the Long?

Code:
// Load PanelRedeemAddress
PanelRedeemAddress panelRedeemAddress = (PanelRedeemAddress) session.load(PanelRedeemAddress.class, panel.getId());


just use panel, instead of panel.getId()

Code:
<class name="com.lsr.eclipse.framework.core.model.PanelRedeemAddress" table="panel_redeem_address">
<id column="panel_id" name="id" type="java.lang.Long">
<generator class="foreign">
<param name="property">panel</param>
</generator>
</id>
<one-to-one name="panel" class="com.lsr.eclipse.framework.core.model.Panel" constrained="true"/>
<property column="street1" length="50" name="street1" not-null="true" type="java.lang.String"/>
<property column="street2" length="50" name="street2" type="java.lang.String"/>
<property column="city" length="25" name="city" not-null="true" type="java.lang.String"/>
<property column="state" length="4" name="state" not-null="true" type="java.lang.String"/>
<property column="zipcode" length="15" name="zipcode" not-null="true" type="java.lang.String"/>
<property column="phone" length="25" name="phone" type="java.lang.String"/>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 4:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you have a Panel, you should have an association to PanelRedeemAddress I suppose. Then you can just to panel.getRedeemAddress() to get the adress.

If you dont map it, you can still do a query like:

Code:
session.createQuery("from PanelRedeemAddress p where p.panel = :panel").setParameter("panel", panel).uniqueResult()


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.