Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » help with moving to JPA(Please provide tips/gotchas for moving to JPA)
help with moving to JPA [message #548122] Tue, 20 July 2010 13:35 Go to next message
Larry  is currently offline Larry
Messages: 30
Registered: December 2009
Member
I have been reviewing JPA and would like to use it with one of our applications as a test. Can anybody provide tips on how to handle the problems with moving an existing app/DB to JPA.

A lot of the tables will match up to entities very well, but there are also those cases where we have sql that really doesn't match any of the existing tables in our DB. Some queries are just for reporting info. They will sum up columns from many tables. Can anyone please provide info on how you handled this?

Any other tips/gotchas would be nice. Is there any thing on the web that would help with this??

Thanks
Re: help with moving to JPA [message #548160 is a reply to message #548122] Tue, 20 July 2010 16:02 Go to previous message
Tom Eugelink is currently offline Tom Eugelink
Messages: 806
Registered: July 2009
Senior Member
I chose to mirror the database model 1-1 to the entities (reverse engineer that part even) and then put an layer on top that mixes stuff.
Views can also be accessed as readonly entities with relationships to other entities.

The biggest gotcha for me was that in relationships, you have to maintain the Java collection equivalents yourself. So in my code a setter automatically calls the adder, which again calls the setter, which calls the adder, and that cycle needs to stop somewhere. So:
Employee's setDepartment(dpt) does "this.dpt = dpt" and then calls dpt.addEmployee(this)
Department's addEmployee(emp) does "this.emps.add(emp)" and then calls emp.setDepartment(this)
This would cause and endless loop, so in both methods I have an break-out line:
if (this.dpt == dpt) return;
And:
if (this.emps.contains(emp)) return;


On 2010-07-20 19:35, Larry wrote:
> I have been reviewing JPA and would like to use it with one of our
> applications as a test. Can anybody provide tips on how to handle the
> problems with moving an existing app/DB to JPA.
>
> A lot of the tables will match up to entities very well, but there are
> also those cases where we have sql that really doesn't match any of the
> existing tables in our DB. Some queries are just for reporting info.
> They will sum up columns from many tables. Can anyone please provide
> info on how you handled this?
>
> Any other tips/gotchas would be nice. Is there any thing on the web that
> would help with this??
>
> Thanks
Previous Topic:new jpa project user library requires javax.persistence.entity
Next Topic:One entity with two sequences
Goto Forum:
  


Current Time: Fri Apr 18 16:49:36 EDT 2014

Powered by FUDForum. Page generated in 0.01428 seconds