In this method, we will create a relationship in such a way that both tables contain the same primary key value for the related record. So, we can say that here we used unidirectional as well as bidirectional relationships, because we can get either record through another record using its primary key. For example, if Person
is inserted with id 1
, you should get the PassportDetail
record inserted with id 1
as well.
Here, we will create Person
and PassportDetail
classes to work this demo.
Use the following script to create the tables if you are not using hbm2dll=create|update
:
Use the following script to create the passport_detail
table:
CREATE TABLE `passport_detail` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `passportno` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) );
Use the following script to create the person
table:
CREATE TABLE `person` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT...