[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

understanding  hibernate mapping tutorial

Posted on 2009-05-17
3
Medium Priority
?
453 Views
Last Modified: 2013-12-29
Here i have attached a  hibernate  Event.hbm.xml file.

I have a query here .

note , we have an entry
<id name="id" column="uid" type="long" unsaved-value="null">  

and also we have entry...

<set name="speakers" cascade="all">
            <key column="event_id"/>
            <one-to-many class="Speaker"/>
        </set>


does that mean hibernate will automatically understand  "id" column  in Event table is a foreign key  "event_id"  column in Speaker table ?

How hibernate will understand that ?i don't see any foreign key tag in the mapping file ....so i am bit confused at this part.

I am not sure , how hibernate will relate these two column .  because i think whenever a value say "1" is saved in "id" field , there will also "1" be saved in event_id column because of this mapping file....right ?



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
 
<hibernate-mapping>
    <class name="Event" table="events">
        <id name="id" column="uid" type="long" unsaved-value="null">
            <generator class="increment"/>
        </id>
        <property name="name" type="string" length="100"/>
        <property name="startDate" column="start_date"
                  type="date"/>
        <property name="duration" type="integer"/>
        <many-to-one name="location" column="location_id" class="Location"/>
        <set name="speakers" cascade="all">
            <key column="event_id"/>
            <one-to-many class="Speaker"/>
        </set>
        <set name="attendees" cascade="all">
            <key column="event_id"/>
            <one-to-many class="Attendee"/>
        </set>
    </class>
</hibernate-mapping>

Open in new window

0
Comment
Question by:cofactor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24409058
>            

that specifies which column is the foreign key for a Speaker
And as it is specified in the Event mapping then it relates to the Event class

0
 

Author Comment

by:cofactor
ID: 24409163
the DDL has been given as below in the tutorial

create table events (uid int ,
name varchar,
start_date date,
duration integer,
location_id int)


create table speakers (uid int,
firstName varchar,
lastName varchar,
event_id int)


but  there is no FK constraint put in this  DDL  .....shall  we need to put constraints here ?
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 24409167
up to you, not necessary to make it work.
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question