• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Mapping help required

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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.
 
Anoop Raj
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic