• 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 Association

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

1. In hibernate orm concepts are seems like similar to the database relational linking, where as what is the advantage of having orm because we have the database relational technique so why would i need to go for orm

2. in hibernat association for many to one like user_master table user id have lot of expense id in expense_master table and i have done all mapping like i pasted the code below so my question is

while i am fetching the user i can get all expense detals but while inserting the expense, shall i need load the user in expense pojo ? same when i inser user do i need to set any expense objects?

if any links or words to explain association please let me know it bit confusing

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 19, 2009 8:17:22 AM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="ZuserDetail" table="zUSER_DETAIL" schema="dbo" catalog="EMONITERING">
<id name="userId" type="int">
<column name="USER_ID" />
<generator class="assigned" />
</id>
<property name="username" type="string">
<column name="USERNAME" length="500" />
</property>
<property name="password" type="string">
<column name="PASSWORD" length="2000" />
</property>
<property name="dob" type="timestamp">
<column name="DOB" length="23" />
</property>
<property name="email" type="string">
<column name="EMAIL" length="200" />
</property>
<property name="paddress" type="string">
<column name="PADDRESS" length="1000" />
</property>
<property name="caddress" type="string">
<column name="CADDRESS" length="1000" />
</property>
<property name="status" type="java.lang.Character">
<column name="STATUS" length="1" />
</property>
<property name="createTimeStamp" type="timestamp">
<column name="CREATE_TIME_STAMP" length="23" />
</property>
<set name="loginDatas" inverse="true" lazy="true" table="LOGIN_DATA" fetch="select">
<key>
<column name="USER_ID" />
</key>
<one-to-many class="LoginData" />
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 19, 2009 8:17:22 AM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="LoginData" table="LOGIN_DATA" schema="dbo" catalog="EMONITERING">
<id name="loginTypeId" type="int">
<column name="LOGIN_TYPE_ID" />
<generator class="assigned" />
</id>
<many-to-one name="zuserDetail" class="ZuserDetail" fetch="select">
<column name="USER_ID" />
</many-to-one>
<property name="loginType" type="string">
<column name="LOGIN_TYPE" length="50" />
</property>
<property name="username" type="string">
<column name="USERNAME" length="50" />
</property>
<property name="password" type="binary">
<column name="PASSWORD" />
</property>
<property name="status" type="java.lang.Character">
<column name="STATUS" length="1" />
</property>
<property name="createdTimeStamp" type="timestamp">
<column name="CREATED_TIME_STAMP" length="23" />
</property>
</class>
</hibernate-mapping>
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

G.Sathish kumar wrote:1. In hibernate orm concepts are seems like similar to the database relational linking..


Domain model and the relational model has differences in their structure (this is called Object Relational Impedance mismatch). For example, In domain model - We use references to related objects. In relational model - We have foreign keys to other relations in the schema.

where as what is the advantage of having orm because we have the database relational technique so why would i need to go for orm


There are lots of things ORM handles for us than using plain JDBC code. For example when populating objects from ResultSet we have to manually use setters/constructors but the ORM handles that for us when properly mapped (And we don't have to write those redundant code in all places). There are many more ....

 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Vijitha Kumara

Thanks for your valuable info

i have doubt about association like
1. when i associate user with bank and the case where user have many bank object so when i try to insert bank should we need to load the user object inside of bank or is not required?
2. about point one in the case of many to many relation ship how to handle?
2. what is the advantage of implement association in hibernate instead of develop project without hibernate association?
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. when I associate user with bank and the case where user have many bank object so when I try to insert bank should we need to load the user object inside of bank or is not required?

ANS-: You should initialise user and then add bank object to it. If bank can not be without user put not null constraint on the user in bank object.
in add bank method of user use bank.setUser(this) to maintain relation.


2. about point one in the case of many to many relation ship how to handle?
I am not able to get the scenario can you please specify more? but if your question is about how to map then you will require a mapping table in middles something like user_bank_group where one column is user id and other is bank.

3. what is the advantage of implement association in hibernate instead of develop project without hibernate association?
Well there are many ORM advantages while writing queries, managing data and association.
Few are it will be lot quicker to develop as you can concentrate on business logic rather than stuff like writing logic to retrieve and convent to objects, you can manage whether every time user object is created whether to fetch all banks with it always or bring from db only when needed.

Hope this helps
 
This tiny ad will self destruct in five seconds.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic