-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: One Object to Multiple Table Mapping
PostPosted: Tue Jan 03, 2006 12:37 am 
Newbie

Joined: Wed Nov 30, 2005 9:04 am
Posts: 8
Location: Bangalore
I have a single object with two items in it. I want to write the contents of this object to two differant tables using hibernate, where each table will take a single item from the object.

A simple example is given below

Object contains
name,
address

and the two tables are

name_table
address_table

where name will be written to name_table,
address will be written to address_table

The two tables are having a 1-1 (primary key – foreign key) relationship


My questions are:

1.I would like to know if it is possible to write in such a manner into the DB tables from a single object.

1.If yes
a.will the foreign key also be written to the second table by hibernate automatically or do we have to use some indirect mechanism to do this

b.then could someone possible point out how one should go about writing the mapping file for it

1.Does anyone know if any documentation is available explaining Hibernate mapping files and its syntax and how one can go about writing it from scratch, instead of referring to examples to learn it.

respond to me in piku.mishra@gmail.com

_________________
Piku Mishra


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 9:31 am 
Newbie

Joined: Mon Dec 26, 2005 12:00 pm
Posts: 8
1. Yes, this is possible. There's an element called <join table=...> that does exactly that.

The following example shows the general sketch of your mapping file:

Code:
<hibernate-mapping>
    <class name="YourClassName" table="NAME_TABLE">
        <id name="id" column="ID" type=...>
            <generator class=... />
        </id>

        <!-- properties related to columns in the main table -->
        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            column="NAME"
        />

        <!-- here comes the magic... -->
        <join table="ADDRESS_TABLE">
            <key column="ID"/>

            <!-- properties related to columns in the joined table -->
            <property
                name="address"
                type="java.lang.String"
                update="true"
                insert="true"
                column="ADDRESS"
            />

        </join>
    </class>
</hibernate-mapping>


In general, this mapping handles most of what you need.

2. The reference documentation is at http://www.hibernate.org/hib_docs/reference/en/html/index.html. The main reference book is "Hibernate in Action", written by Christian Bauer and Gavin King. Unfortunately, this book refers to Hibernate 2.x, which is somewhat deprecated -- currently we're at Hibernate 3.1. Anyway, the new edition should be published in the next few months.

_________________
Best regards,
Vilar Camara Neto

(please, don't forget to vote...)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.