-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: @ManyToOne and inner join
PostPosted: Thu May 08, 2008 9:12 am 
Newbie

Joined: Thu May 08, 2008 9:00 am
Posts: 4
Hibernate version: 3.2.1.ga

Hi,

I am using JPA and Hibernate as JpaVendor.
I have some @ManyToOne relations. Hibernate generates LEFT OUTER JOIN for the SELECT statements. I wish to use INNER JOIN for some of the selects. I have tried with
Code:
@ManyToOne(optional=false)

and
Code:
@JoinColumn(name="id", nullable=false, unique=true)


This does not have any effect. Is there some way to achieve an INNER JOIN, using annotations?


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 10:11 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

there is the @Fetch annotation, but I believe that even if you specify JOIN you will end up with an outer join. In fact there seems to be a jira issue for that: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1940.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 09, 2008 6:38 am 
Newbie

Joined: Thu May 08, 2008 9:00 am
Posts: 4
Thanks for your reply.

I got it working with JPQL.
It seems like Hibernate generates more queries than neccessary though.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 09, 2008 10:02 am 
Newbie

Joined: Fri May 09, 2008 9:57 am
Posts: 1
Hi borgel,

I am having same issue (want inner join but hibernate keep doing left outer join) with manytoone annotation and I tried few things and can not get it working. Can you please tell me how you fix this issue.

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 5:57 am 
Newbie

Joined: Thu May 08, 2008 9:00 am
Posts: 4
Hi Spa,

sorry for my very late reply.

Instead of em.find(entityClass, primaryKey) i did the following:
Query q = em.createQuery("SELECT customer FROM Customer customer WHERE customer.id=:id");
q.setParameter("id", id);

myCustomer = (Customer)q.getSingleResult();

This results in several queries, but the result is as expected. I don't think it is possible to get Hibernate to do inner joins.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 6:12 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

I have used Hibernate via JPAQL to generate inner joins, do the following:

Code:
em.createQuery("SELECT me FROM MyEntity me INNER JOIN me.<many to one getter>");


Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 8:17 am 
Newbie

Joined: Thu May 08, 2008 9:00 am
Posts: 4
andydale wrote:
Hi,

I have used Hibernate via JPAQL to generate inner joins, do the following:

Code:
em.createQuery("SELECT me FROM MyEntity me INNER JOIN me.<many to one getter>");


Cheers,

Andy


I also tried this, but when I looked at the queries Hibernate generated it was a lot of other queries going on...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.