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!