-->
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: Problems with generated SQL in SQL Server 2000
PostPosted: Fri Apr 25, 2008 4:17 pm 
Newbie

Joined: Fri Apr 25, 2008 3:18 pm
Posts: 1
Hi,

I've been having some problems with hibernate generated SQL. I'm getting an error when trying to load a mapped collection of a class. This error occurs when using both hibernate versions below.

Hibernate version: 3.2.5.ga and 3.2.6.ga

Here are my annotated classes:

Mapping documents:

Code:
@Entity
@Table(name = "tabProcessoJudicial")
public class ProcessoJudicial implements Serializable {
    /** Serial Version UID. */
    private static final long serialVersionUID = -3680243056645774355L;

    @Id
    @GeneratedValue
    @Column(name = "ProcessoJudicialID")
    private final Long id;

    @OneToMany(mappedBy = "processoJudicial")
    @OrderBy("dataAndamento desc")
    private List<HistoricoAndamento> historicoAndamentos;

    ...
}

@Entity
@Table(name = "tabProcessoMesaTarefa")
public class ProcessoMesaTarefas implements Serializable {
    /** Serial Version UID. */
    private static final long serialVersionUID = -7716574692719999485L;

    @Id
    @GeneratedValue
    @Column(name = "ProcessoMesaTarefaID")
    private final Integer id;

    @ManyToOne
    @JoinColumn(name = "ProcessoJudicialID")
    @Basic(optional = false)
    private ProcessoJudicial processoJudicial;

    @OneToMany(mappedBy = "processoMesaTarefas")
    @OrderBy("dataAndamento desc")
    private List<RegistroTarefa> tarefasRegistradas;
    ...
}

@Entity
@Table(name = "tabHistoricoAndamento")
@Inheritance(strategy = InheritanceType.JOINED)
public class HistoricoAndamento implements Serializable {
    /** Serial Version UID. */
    private static final long serialVersionUID = 5916799770173601896L;

    @Id
    @GeneratedValue
    @Column(name = "HistoricoAndamentoID")
    private final Long id;

    @ManyToOne
    @JoinColumn(name = "ProcessoJudicialID")
    private ProcessoJudicial processoJudicial;

    @Column(name = "DataHoraAndamento")
    private Date dataAndamento;
    ...
}

@Entity
@Table(name = "tabRegistroTarefa")
@Inheritance(strategy = InheritanceType.JOINED)
@PrimaryKeyJoinColumn(name = "RegistroTarefaID")
public abstract class RegistroTarefa extends HistoricoAndamento {

    @ManyToOne
    @JoinColumn(name = "ProcessoMesaTarefaID")
    private ProcessoMesaTarefas processoMesaTarefas;
    ...
}


And I still have a few other classes that extend RegistroTarefa.

When I execute the following code against SQL Server 2000, everything works fine:

Code:
...
processoMesa = (ProcessoMesaTarefas) getSession()
    .load(ProcessoMesaTarefas.class, 1);
processoMesa.getProcessoJudicial().getHistoricoAndamentos().size();
...


And here's the generated SQL:
Code:
select ...
from tabHistoricoAndamento historicoa0_ left outer join tabRegistroTarefa historicoa0_1_
       on historicoa0_.HistoricoAndamentoID=historicoa0_1_.RegistroTarefaID
     ...
where historicoa0_.ProcessoJudicialID=?
order by historicoa0_.DataHoraAndamento desc


But, when I execute the code below:

Code:
processoMesa = (ProcessoMesaTarefas) getSession()
    .load(ProcessoMesaTarefas.class, 1);
processoMesa.getTarefasRegistradas().size();


I get the following error:

The column prefix 'tabHistoricoAndamento' does not match with a table name or alias name used in the query.

Here's the generated SQL:

Code:
select ...
from tabRegistroTarefa tarefasreg0_ inner join tabHistoricoAndamento tarefasreg0_1_
       on tarefasreg0_.RegistroTarefaID=tarefasreg0_1_.HistoricoAndamentoID
     ...
where tarefasreg0_.ProcessoMesaTarefaID=?
order by tabHistoricoAndamento.DataHoraAndamento desc


When I remove the annotation '@OrderBy("dataAndamento desc")' from 'tarefasRegistradas' in the class 'ProcessoMesaTarefas', everything works fine.
Is there a problem with the class mapping? Or maybe with SQLServer? Is there a work around?

Thanks in advance,

André Rodrigues


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.