aspose file tools
The moose likes Object Relational Mapping and the fly likes Hibernate Mapping help required Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate Mapping help required" Watch "Hibernate Mapping help required" New topic
Author

Hibernate Mapping help required

Anoop Raj
Greenhorn

Joined: Aug 08, 2006
Posts: 2
All,

We have two tables, Measure and Measure_Values. The Measure_values table has a composite primary key. Hibernate mappings for both tables are given below.

Issue Values are not saved into the Measure_values table and hibernate doesnt throw any exceptions.


Create table measure(measure_id number primary key,measure_nm varchar2, measure_type varchar2);

Create table measure_value(measure_id number, dim_id number, dim_value varchar2); ) (measure_id & dim_id as primary_key

Mappings:

Code:

<class name="Measure" table="MEASURE">
<id name="measureId" column="MEASURE_ID" type="long">
<generator class="sequence">
<param name="sequence">MEASURE_SEQ</param></generator>
</id>
<property name="name"
column="MEASURE_NM"
type="java.lang.String" />
<property name="name"
column="MEASURE_TYP"
type="java.lang.String" />
<!-- Define the relationship with measure values -->
<set name="values"
lazy="false"
order-by="DIM_ID"
table="MEASURE_VALUE"
cascade="save-update,persist">
<key column="MEASURE_ID"/>
<one-to-many class="MeasureValue"/>
</set>
</class>

<!-- Define the mapping for Measure Value -->
<class name="MeasureValue" table="MEASURE_VALUE">
<composite-id>
<key-property
name="dimensionId"
type="long"
column="DIM_ID" />
<key-property
name="measureId"
type="long"
column="MEASURE_ID" />
</composite-id>
<property name="dimensionValue"
column="DIM_VALUE"
type="java.lang.String"/>
</class>
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 504




Anoop,
I see two columns are mapped with the same name. You would not even be able to read your hibernate config fully without errors. you'd get a MappingException from hibernate.
Also I dont see any mapping for measure_seq.

and.. It would be easy to read code if it is posted within the code tags which are available.
Also post how you are using hibernate to store the values in DB.


If you are not laughing at yourself, then you just didn't get the joke.
Anoop Raj
Greenhorn

Joined: Aug 08, 2006
Posts: 2
Thanks Arun,

My bad, the mapping had too many fields, i just added two properties for asking the question. The mapping file is correct.

For saving, i am creating and instacnce of the Parent calss and calling saveOrUpdate in the hibernate template.

 
 
subject: Hibernate Mapping help required
 
Threads others viewed
Set- Key Mapping issue with nested-composite-element
Foreign key must have same number of columns as the referenced primary key
Hibernate: Foreign key must have same number of columns as the referenced primary key
Mapping Problem in Hibernate
Mapping document query
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture