The JPA 2.0: Basic starting

As I’ve mentioned at my previous post Apache Derby Part 3, about the JPA preparation as creating 3 tables, the master table, the detail table which is one-to-many relationship with master and the look up table which is one-to-one relationship to the master.

I’ve created these 3 tables in Apache Derby by mentioning the relationship explicitly via the foreign key constraint. Then I use NetBeans to generate the JPA and create some testing about the basic CRUD and take more attention to the child data management via the POJO accessing through LIST or COLLECTION e.g. create new elements, update or delete elements. For sure, when save the parent object, all related child objects changing will be applied  automatically without any line of code.

I finally found it is named a cascading event and orphan removal based on the relationship among the entities. Then it’s quite lucky I define that relationship explicitly so that the further investigating and trying is not required. I, personally, though It is nice to follow the standard.

Please note, my JPA example code follows the “Java EE 5 Tutorial”, Part V: Persistence”. You can download it from Sun/Oracle web site or search it via Google, it will take you to the downloading area.

Even I follow the Java EE 5 example code, it is worked fine at the Java EE 6: JPA 2.0 as well. The difference is via the JPA 1.x, I need to manage the detail changing by implement some coding and keep tracking and maintaining states by myself explicitly, but not for the JPA 2.0, all changing will be done by the JPA engine as mentioned above.

As the subject of this article, it is a basic starting. I will quick jump to the EJB 3.1 with purpose to capture and understand the whole big picture of new technology as fast as possible. I prefer the iterative action for my experimental learning by starting from the total picture and the move further to the detail part over and over.

About Charlee Chitsuk

I've been working as a software developer since 1998. At the moment I focus on system integration including with SOA and Enterprise Security Solution.

Posted on June 17, 2010, in JPA and tagged . Bookmark the permalink. Leave a comment.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: