Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » JPA Questions(How and when to use JPA)
JPA Questions [message #531087] Mon, 03 May 2010 12:30 Go to next message
Eclipse UserFriend
I have a few questions.

I am trying to figure out when and why to use JPA. I have done some tutorials and came to the following conclusions/questions.

1) JPA is great for returning entities rather than having to use JDBC to map over the fields.

2) Trying to figure out how to design entities can be really hard. You can not just take the DB table and call it an entity (you can sometimes, but not alot). I have the situation of converting over an application that has lots of joins. Now do I always have to design a relationship in an entity so that I can use it as a join? For instance, if I have entity A and entity B, and I want to get all records for A that have a join relationship with entity B. Do I have to have Entity B mapped into entity A? I would have preferred to just use a NamedQuery to get the data and join in B. But if the Entity (B) is not defined/mapped into entity A, I don't believe you can do this. Is this when you use a native query? Or is it a design flaw on my part. I can see a lot of these situations where I am querying for data with mutlitple table joins. I also see a lot of instances where I don't want to always have to create a relationship with the other entities. I could see where I have an Entity that has about 20 different joins to other entities/tables due to returning different sets of data using the same table/Entity. I don't think it would be good design to have the join tables mapped to one entity. Am I just missing something??

3) Also, I had a few problems with outer joins. When I used the following code:
select a from A a LEFT OUTER JOIN a.b b
where a.id = b.id and b.id2 = 1;
It worked except when there was no match on b, then it returned nothing. It should return entity A even if b was not found (our did I get the LEFT OUTER JOIN definition wrong?).

Any help would be appreciated!!!!
Re: JPA Questions [message #531951 is a reply to message #531087] Thu, 06 May 2010 11:07 Go to previous message
Eclipse UserFriend
2) Yes, designing a good object model can be difficult, as designing a good data model. The are tools such as Eclipse Dali that can generate a JPA object model from the data model, and generate relationships based on the database constraints.

Most object oriented developers would recommend an object model be developed to meet the application requirements and correctly model the business domain.

3) An outer join means the join condition will return a null row if there are no rows that meet the join condition. If you filter the joined row in the where clause, then this will be filtered.

i.e.
select a from A a LEFT OUTER JOIN a.b b
where a.id = b.id and b.id2 = 1;

Will not return any a's where the b.id2 is not equal to 1.

If you also want a's that don't have a b you need,

select a from A a LEFT OUTER JOIN a.b b
where b.id2 is null or b.id2 = 1

or,
select a from A a LEFT OUTER JOIN a.b b
where a.b is null or b.id2 = 1

Previous Topic:Mapping two objects on same table
Next Topic:Filtering a OneToMany relationship
Goto Forum:
  


Current Time: Wed Jul 23 01:01:54 EDT 2025

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

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

Back to the top