Just Hibernate by Madhusudhan Konda

Just Hibernate by Madhusudhan Konda

Author:Madhusudhan Konda
Language: eng
Format: epub, mobi, pdf
ISBN: 9781449334376
Publisher: O’Reilly Media, Inc.
Published: 2014-10-26T16:00:00+00:00


Now let’s see how we do mapping for a one-to-one association. The mapping for the Car object against the CAR table is given here, in a Car.hbm.xml file:

<hibernate-mapping package="com.madhusudhan.jh.associations.one2one"> <class name="Car" table="CAR"> <id name="id" column="CAR_ID"> <generator class="assigned"/> </id> <property name="name" column="NAME"/> <property name="color" column="COLOR"/> <one-to-one name="engine" class="Engine" cascade="all"/> </class> </hibernate-mapping>

By now, this mapping should be familiar to you.

The id is set by the application, and the relevant properties are mapped to the table columns. Did you notice how the engine property was set? A one-to-one mapping tag is used to associate the engine to the Car. What this notation is truly saying is:

The instance of the Car (it is defined for the Car class) has a property called engine.

Car and Engine exhibit a one-to-one association.

Engine is set by values pulled from the ENGINE table (which is mapped to the Engine object).



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.