Skip to main content


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 17:35 Go to next message
Larry  is currently offline Larry Friend
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 20:02 Go to previous message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
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: Tue Apr 23 06:15:19 GMT 2024

Powered by FUDForum. Page generated in 0.03160 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top