Hello ,
Trying to learn JPA .
Am trying an example of Master Child relation but using One to One Mapping
The mapping is unidirectional .
"User" is the "Master Table" ( fields are :: id ( PK ) , name ( varchar )
"UserAddress" is Child Table with a foreign key referencing "User"
( fields are :: id ( PK ) , street (varchar) , uid( fk references id field of User table )
Here is my
Java Code ::
User Class ::
Here is the Child class ::
Here is the
test method ::
This works fine for me
However I dont want to compose my userAddress object with User Object
Want to do it the other way around
Also want to maintain unidirection one to one mapping
( From User to UserAddress )
No Change in Database tables ::
User will be master table with UserAddress As the Child table containing foreign key .
Here is the changed code that I tried ::
Parent class ::
Child Class ::
Test code ::
Here there are no errors .
Records are getting inserted in both parent and child
However the child table is getting a null in the foreign key column .
Any ideas will be greatly appreciated .
Regards,
-anagha