-->
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.  [ 1 post ] 
Author Message
 Post subject: Avoid unnecessary join on inheritance with JOINED strategy
PostPosted: Fri Aug 15, 2014 11:15 am 
Newbie

Joined: Fri Oct 11, 2013 7:43 am
Posts: 2
I'm using JPA 2 with Hibernate 4.2.0-Final as provider and I have the following entities:

Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Person {

    @Id
    private String id;

    .. Person attributes ..
    .. Getters/Setters ..
}

@Entity
@Table(uniqueConstraints={@UniqueConstraint(name="UniqueCode", columnNames="code")})
public class Customer extends Person {

    @Column(nullable=false)
    private String code;

    .. Other Customer attributes ..
    .. Getters/Setters ..
}


And I have the following JPQL:

Code:
SELECT count(distinct c.code) FROM Customer c


For which Hibernate is generating the following SQL:

Code:
select
    count(distinct customer0_.code) as col_0_0_
from
    Customer customer0_
inner join
    Person customer0_1_
        on customer0_.id=customer0_1_.id


But I only need to count Customers with distinct code, which happens to be a field that is specific to Customer. I don't need any field/attribute stored on subclass or parent class, so there is no need for the inner join to 'Person'. I'd like Hibernate to generate the SQL like follows (i.e. without joinning table 'Person'):

select
count(distinct customer0_.code) as col_0_0_
from
Customer customer0_

Is there a way to tell Hibernate to avoid the unnecessary inner join?

Thanks,
Rafael.


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

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.