Hi all,
This is my 2nd week using Hibernate and I've been pretty impressed and overwhelm by all the features. Currently, I am trying to map a "derived property" and not sure the right way to go about it. Here's the problem statement:
I have three tables:
table: SHIRT
ID NUMERIC
SIZE VARCHAR
DESCRIPTION VARCHAR
table: APPLE
ID NUMERIC
COLOR VARCHAR
table: SELLABLE_ITEM_TYPE
ID VARCHAR
NAME VARCHAR
The SELLABLE_ITEM_TYPE table contains only two rows, one for SHIRT and one for APPLE, as you may have guessed.
The Shirt bean contains the following properties: id, size, description, and type. The mapping for all the properties is pretty straightforward, except type.
Type is of a SellableItemType object. I'm not quite sure how to tell Hibernate to map this.
A few things I've tried:
Code:
<one-to-one name="type" >
<formula>id</formula>
<formula>'SHIRT'</formula>
</one-to-one>
but obviously this won't work since SELLABLE_ITEM_TYPE and SHIRT table does not share any property-ref. Is there a way to tell Hibernate that there's no property ref?
Another thing I've tried is using formula and property:
Code:
<property name="type"
type="com.blah.SellableItemType"
insert="false" update="false"
formula="select * from SELLABLE_ITEM_TYPE SI where SI.ID='SHIRT''"
/>
and I'm getting this error:
Code:
Caused by: java.sql.SQLException: Syntax error or access violation, message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select * from SELLABLE_ITEM_TYPE SI where SI.ID='SHIRT' as' at line 1"
What's the right way to use formula here? Is it possible to map a formula expression to a complex object?
I read through a few posts but couldn't find similar items discussed. My apology if this is a common question. If so, please send a clue my way so I can narrow my search. Thanks!