-->
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: Incorrect Generated SQL
PostPosted: Thu Jan 12, 2012 4:00 pm 
Newbie

Joined: Thu Jan 12, 2012 1:55 pm
Posts: 2
I have the following classes:

Super Class Pessoa
Code:
@Entity
@Table(name = "pessoa", schema = "cadastro")
@Inheritance(strategy = InheritanceType.JOINED)
public class Pessoa implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(...GENERATE STRATEGY)
    private Integer idpessoa;
//... FIELDS, GETERS AND SETTERS


Child Pessoa Fisica
Code:
@Entity
@Table(name = "pessoa_fisica", schema = "cadastro")
@PrimaryKeyJoinColumn(name = "pessoa")
public class PessoaFisica extends Pessoa {
//... FIELDS, GETERS AND SETTERS


Another Child Pessoa Juridica
Code:
@Entity
@Table(name = "pessoa_juridica", schema = "cadastro")
@PrimaryKeyJoinColumn(name = "pessoa")
public class PessoaJuridica extends Pessoa {
//... FIELDS, GETERS AND SETTERS


When i execute the following query...
Code:
SELECT new PessoaFisica(pf.idpessoa, pf.nome, pf.cpf) FROM PessoaFisica pf

I get the error: column pessoafisi0_.idpessoa does not exist because Hibernate try generate the query using child table alias and the field name from the parent table on line 2
Generated Query:
Code:
select
        pessoafisi0_.idpessoa as col_0_0_,
        pessoafisi0_1_.nome as col_1_0_,
        pessoafisi0_.cpf as col_0_1_,
    from
        cadastro.pessoa_fisica pessoafisi0_
    inner join
        cadastro.pessoa pessoafisi0_1_
            on pessoafisi0_.pessoa=pessoafisi0_1_.idpessoa


The correct is get field pessoa from pessoafisi0_ (Child Table) or field idpessoa from pessoafisi0_1_ (Parent Table)
pessoafisi0_.idpessoa as col_0_0_ -> WRONG
pessoafisi0_.pessoa as col_0_0_ -> CORRECT
pessoafisi0_1_.idpessoa as col_0_0_ -> CORRECT

If i do the same with PessoaJuridica the query was generated with success as follows:
Query:
Code:
SELECT new PessoaJuridica(pj.idpessoa, pj.nome, pj.cnpj) FROM PessoaJuridica pj

Generated Query:
Code:
select
        pessoajuri0_.pessoa as col_0_0_,
        pessoajuri0_1_.nome as col_1_0_,
        pessoajuri0_.cnpj as col_2_0_
    from
        cadastro.pessoa_juridica pessoajuri0_
    inner join
        cadastro.pessoa pessoajuri0_1_
            on pessoajuri0_.pessoa=pessoajuri0_1_.idpessoa


Using Hibernate Core 4.0.1, Hibernate Entity Manager 4.0.1, Hibernate Commons Annotations 4.0.1 and Spring 3.1
Am i doing something wrong or this is a bug?
Sorry bad english :(

Thanks in advance!


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.