aspose file tools*
The moose likes Object Relational Mapping and the fly likes HBM mapping Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HBM mapping Problem" Watch "HBM mapping Problem" New topic

HBM mapping Problem

vivek kumar jaiswal

Joined: Jul 31, 2008
Posts: 24

Hello Ranchers,

Please see this mapping.

<class name="User" table="users">
<id name="id" column="id">
<generator class="identity" />
<discriminator column="user_type" type="string" />
<version name="version" column="version" />

<bag name="pchDetails" table="user_pch" lazy="false" inverse="true">
<key column="user_id"/>
<many-to-many column="pch" class="PchDetail"/>
<bag name="workcenters" table="user_workcenter" inverse="true"
<key column="user_id" />
<many-to-many column="workcenter_id" class="Workcenter" />
<property name="firstName" column="first_name" />
<property name="middleName" column="middle_name" />
<property name="lastName" column="last_name" />
<property name="tokenNumber" column="token_number" />
<property name="userId" column="user_id" />
<property name="hashedPassword" column="hashed_password" />
<property name="randomCookie" column="random_cookie" />
<property name="userState" column="user_state" />

<class name="UserPch" table="user_pch">
<key-property name="pchDetail" column="pch"/>
<key-property name="user" type="string" column="user_id"/>
<many-to-one name="user" class="User" lazy="false" column="user_id" insert="false" update="false"/>
<many-to-one name="pchDetail" class="PchDetail" lazy="false" column="pch" insert="false" update="false"/>
<property name="tdate" type="java.util.Date" column="tdate"/>

<class name="PchDetail" table="pch_detail">
<id name="pch" column="pch"/>
<property name="pch" column="pch" insert="false" update="false"/>

Check this mapping

<bag name="pchDetails" table="user_pch" lazy="false" inverse="true">
<key column="user_id"/>
<many-to-many column="pch" class="PchDetail"/>

The value of "user_id" column in "user_pch" table saved the value of "id" column in "users" table.

I want to save user_id column in users table to user_id column in user_pch.

Please what should I do.


Waswani Naresh
Ranch Hand

Joined: May 01, 2008
Posts: 66
Hi Vivek,

I was not very comfortable with the concern/question that you have. I tried to simulate some thing similar using layman POJOs and mappings. Have a look at them and see if this helps to solve your problem.




Main code for saving objects :


Naresh Waswani
vivek kumar jaiswal

Joined: Jul 31, 2008
Posts: 24

Dear Naresh,

thanking to replying this concern i solved this problem.

<key column="user_id" property-ref="UserId"/>


I agree. Here's the link:
subject: HBM mapping Problem
Similar Threads
Hibernte will delete rows from a table, but it won't insert rows
Auto Generator in composite key
Need many-to-one mapping help
Why a select statement, not an insert ?
JPA many-to-many with extra attribute