-->
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: One-to-one domain object mapping
PostPosted: Mon Feb 14, 2005 4:55 pm 
Newbie

Joined: Thu Feb 10, 2005 1:46 pm
Posts: 1
Location: Boston, MA
Hibernate version: 2.1

Code between sessionFactory.openSession() and session.close():
ProductBean product = (ProductBean) session.load(ProductBean.class, new Integer(40));

Name and version of the database you are using:
MySQL 4.0.21

I have a Product object that contains a Status object and I can't figure out how to map it in product.hbm.xml file. The object relationship is the following

Code:
class Product {
private int id;
private String name;
private StatusCode status;
}



... and my StatusCode object
Code:
class StatusCode {
private int id;
private String code;
private String description
}


The relational db model goes like this...
table product (
id int(11),
name varchar(100),
status_code int(11)
)

table product_status (
id int(11),
code varchar(30)
description text
)

Where product.status_code is essentially a foreign key to the domain table product_status. When I retrieve a Product object, I want to retrieve the entire status data as well. However, I can't seem to represent this relationship in my mapping files. I've tried using a one-to-one mapping and component mapping but I can't figure out how to make either work. Something tells me I could represent this relationship with the new <join> element but that's only in Hibernate v3 and I'm using 2.1

Does anyone have any suggestions? I'm new to hibernate and am trying to evaluate whether I should use hibernate to replace current data access layer of my app.

Thank you in advance for your help!


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.