File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes How to Write Left Outer Join Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to Write Left Outer Join" Watch "How to Write Left Outer Join" New topic
Author

How to Write Left Outer Join

dinesh thalis
Ranch Hand

Joined: Nov 19, 2008
Posts: 39
Below show my query, In here main table is "Account" , Joining table is "Customer". How can I write left outer join.



Account Entity




Customer Entity



Please How can I resolve it.
Thank You.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well there are two issues. 1) you have a projection query. which means you get an Object[] back or a List<Object[]> depending on the number of rows.

2) In your From clause you use the JOIN clause. so

FROM Customer c JOIN c.address a

To join a Customer with an Address. By default it will use a Left Outer Join.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
dinesh thalis
Ranch Hand

Joined: Nov 19, 2008
Posts: 39
Thanks for reply, so I want to create outer join but that table(secondary) haven't relation with main table, In that case how can I create it.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Do you guys have a standard where you have to put all those annotations in your class, because for all those properties of your class that are the same name as the corresponding database field name doesn't need any Annotation. The smart defaults are all set to match what you have as those Annotations.

So you don't have an assocation mapping between those two class, but still want a left outer join. I would try two things

First, try just adding a "(+)" on the optional side, just like you would in SQL.

If that doesn't work, use SQL instead and use the "(+)" on the optional side.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Write Left Outer Join
 
Similar Threads
JPA Composite PK with FK problem
How to add JPA ManyToMany records?
EJB3 Beta Certification - EntityManager BASIC notes. (PART II)
JPA2.0 CascadeType.ALL doesn't cascade persist
Edit primary key, if it's a foreign key