| |
Struts Tutorials:
Struts2 Tag CheckBoxList , Checkbox, Iterator, IF
Struts2 Tag Library Example
Struts2 Tiles Example
Struts2 Tiles I18N Example
Struts2 Questions
Struts Tiles I18N Example
Struts Eclipse MVC
Struts2 Tags
Struts2 Example and Tutorial
Struts MVC
Struts2 Validation
Hibernate Tutorials:
Hibernate Case Study
Class Hierarchy Persist Example
Using Hibernate Interceptor
Hibernate Questions with Answer
Hibernate Many-to-Many Mapping Example
Hibernate one-to-many Mapping Example
Hibernate and ORM tools
Spring Hibernate Example
Hibernate SessionFactory Example
Hibernate Mapping Class Hierarchy
Hibernate Questions
Hibernate SessionFactory Questions
Spring Hibernate Example:
Spring Hibernate Case Study
Written By : Amit
Title :
ways create Hibernate SessionFactory
Description :
Example More...
|
Written By : Amit
Title :
Spring Hibernate Integration example
Description :
Example More...
|
Written By : Amit
Title :
ORM Hibernate Best FIT
Description :
Discussion More...
|
Written By : Amit
Title :
One to Many mapping example
Description :
Code More...
|
Written By : Amit
Title :
Many to Many Mapping Example
Description :
code More...
|
Written By : Amit
Title :
Interview questions answer
Description :
discussion More...
|
Written By : Amit
Title :
Interceptor use log SQL statements
Description :
example code More...
|
Written By : Amit
Title :
Class Hierarchy Persist example
Description :
code More...
|
| Tags/Keywords : Hibernate Mapping Question, Hibernate, Mapping, Question,one-to-one,mapping question Author : Amit Date (Year/Month/Date): 2010-04-03
Hibernate one to one type mapping question with
my answer, please do comment on this please. | |
Please be informed that NONE of the design/code/matter from this page is claiming to be some
sort of best practice and we DO NOT expect any of our visitor/reader of this page to assume
this as some sort of best practice for any context and should not be using this as it is
without appropriate evaluation.
This page intends only to provide bits and pieces of known ways for doing some sort of example
and may not be fit for any other purpose.
In spite of all precautions taken to provide accurate and avoid any typo in these pages,
there might be some issues like grammatical mistakes and typo being observed in these pages,
We extend our sincerest apologies for the same.
Hibernate mapping interview question :
Recently someone asked me a very basic question, but actually
I was little bit confused to reply answer to this
particular question.
This questions is targeted towards the mapping of POJO
bean with the corresponding table from persistence
in an one to one style of Hibernate mapping.
The question is as follows:
Can there be Hibernate mapping possible between two
POJOs using two different tables in persistence,
whereby these tables are having primary keys, but
no associated foreign key in either table?
If I try to elaborate taking a simple example, there
are two POJOs A and B, are to be associated with
each other in form of Mapping, whereas table for A
and B are for example TA and TB respectively.And
TA is having a primary key as sample_id_a and TB has
primary key as sample_id_b. but these tables are not
related with each other in any kind of relational
constraint, such as primarykey-foreignkey constraint.
Is this possible??
Well I shall try to show that it is possible to have
one to one mapping (have not tried any other type of
mapping as yet) between these two POJOs in form of
association.
Looking at the Hibernate one to one specific mapping
from one of the example already shown in this site:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="example.iqtf.domain">
<class name="Book" table="book">
<id name="bookId" access="property" column="book_id"/>
<property name="bookTitle" access="property"
column="book_name"/>
<one-to-one name="category"
class="Category" cascade="all"/>
</class>
<class name="Category" table="category" >
<id name="categoryId" access="property"
column="category_id"/>
<property name="categoryTitle" access="property"
column="category_title"/>
</class>
</hibernate-mapping>
|
In this HBM file, we have two POJOs are Book and Category,
associated with each other in a one to one type of mapping.
So Book has a instance variable of type as Category.
Book class is configured to be persisted in table "book",
with book_id as primary key, and Category class persisted
in table category, with the category_id as primary key
constraint defined.
one-to-one tag in Book class tag definition in this HBM
file has the name as category, this means the variable
name is category with type as Category class in the Book
class. So I don't see any mention of foreign key in this
type of mapping. But if the constraint attribute in the
one-to-one mapping is set as "true", then it is required
to have a foreign key constraint defined in the category
table for the book_id primary key in book table.
Hope this helps in finding out one out of many answers.
If you have anything to add to this, you are most welcome.
|
|
|
|
| Home >>> Hibernate Tutorial >>> Hibernate one to one question >>> with answer discussed |
|
|
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
|
|
|
|
|
<- requires login | Log in or Register | |
Copyright © 2008-2010, Interview-Questions-Tips-Forum, All Rights Reserved. | CONTACT PRIVACY POLICY DISCLAIMER |
| |  |
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
Other names may be trademarks of their respective owners
This web site's Terms of Use and Disclaimer :
This web site provides some of the information about various technologies, example code, tips, tutorials etc. Like any printed materials,
content of these pages may become out of date over a period of time. Therefore all visitor/users of this web site are requested/advised
to refer to the originating parties/sources for the latest changes and happenings for detailed information. This information is not
intended to be a substitute for the original reference provided by the originating parties/sources. These examples with source code or
without source code, have not been thoroughly tested under all conditions. Interview-questions-tips-forum.net therefore, cannot guarantee
or imply reliability of these example source code or programs.
By accessing and using this website in any ways, including, without limitation, browsing the website pages, using any information, using
any content and/or downloading any materials, you agree to and are bound by the terms of use described in this page and Usage Terms and Conditions.
If you do not agree to all of the terms and conditions contained in the terms of use described in this page and
Usage Terms and Conditions, do not use this website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use on your employer's behalf.
All Trademarks are property of their respective owner. Appropriate measure is being taken for providing accurate and up-to-date
information but like any printed materials, these blog(s)/contents may eventually be outdated one day, so if you are using any of these
information, please refer original content/documentation from respective sources. And under no circumstances shall the Author of these
contents and/or this web site be liable for any loss, damage, expense incurred or suffered which is claimed to have occurred because of
usage of the contents of this web site. If you have any questions/queries/feedback/suggestions then please write to this web site owner
at contact.
|  |
|
|
|
|
|