Sunday, November 20, 2011

Primary key @OneToOne mapping in Hibernate (JPA)

My main objective is to save/insert as many POJO's as possible with the minimum # of calls to save method. That's why I'm relate them.

But there is a special relationship which it's not clearly documented on the official documentation, and that's why you'll see this entry here :)

.The problem is that I have 2 tables COURSE_ACCESS and COURSE_ACCESS_STATUS:
---------------
COURSE_ACCESS
---------------
*id
...
---------------

---------------------
COURSE_ACCESS_STATUS
---------------------
*course_access_id
...
---------------------

The relationship is 1:1. COURSE_ACCESS is the "parent" table, because that one has the SEQUENCE which generates the PK on "id" column.

Now what I want is when I save COURSE_ACCESS, COURSE_ACCESS_DATA should be saved too. Just like this
How I did it?



And that's it!!! Easy isn't it?

No comments:

Post a Comment