• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

HBM mapping Problem

 
Greenhorn
Posts: 24
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,

Please see this mapping.

<class name="User" table="users">
<id name="id" column="id">
<generator class="identity" />
</id>
<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>
<bag name="workcenters" table="user_workcenter" inverse="true"
lazy="false">
<key column="user_id" />
<many-to-many column="workcenter_id" class="Workcenter" />
</bag>
<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>

<class name="UserPch" table="user_pch">
<composite-id>
<key-property name="pchDetail" column="pch"/>
<key-property name="user" type="string" column="user_id"/>
</composite-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>

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




Check this mapping

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


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.

regards,

vivek
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Proj.java



Empl.java


EmpProj.java



Proj.hbm.xml


Empl.hbm.xml



EmplProj.hbm.xml




Main code for saving objects :




Regards,
Naresh
 
vivek kumar jaiswal
Greenhorn
Posts: 24
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Naresh,

thanking to replying this concern i solved this problem.

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


regards,

VIVEK
 
I like tacos! And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic