-->
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.  [ 2 posts ] 
Author Message
 Post subject: SQL Query generated by Hibernate
PostPosted: Thu Sep 27, 2012 12:31 pm 
Newbie

Joined: Thu Sep 27, 2012 12:12 pm
Posts: 3
I'm a beginner in Hibernate : I try to use annotations.
In purpose i try to use org.hibernate.annotations.LazyCollectionOption.EXTRA

For that on my entity i annotate one member like that :
Code:
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "banque")
   @org.hibernate.annotations.LazyCollection(
         org.hibernate.annotations.LazyCollectionOption.EXTRA)
   private List<CompteEnBanque> listCpt = new ArrayList<CompteEnBanque>();


The Class CompteEnBanque is a SuperClass(with strategy = InheritanceType.TABLE_PER_CLASS), and their two subclasses are "comptes_epargne" and "comptes_courant",

So when I try to get size of listCpt, I have this SQL query generated by Hibernate :

Code:
    select
        count(id)
    from
        ( select
            id,
            plafond,
            solde,
            compteEnBanque_AssuranceID,
            compte_banqueID,
            remuneration,
            1 as clazz_
        from
            comptes_epargne
        union
        select
            id,
            plafond,
            solde,
            compteEnBanque_AssuranceID,
            compte_banqueID,
            null as remuneration,
            2 as clazz_
        from
            comptes_courant
    )
where
    compte_banqueID = ?


And i've got this error : org.hibernate.util.JDBCExceptionReporter - Every derived table must have its own alias
Missing an alias on subselect, how i can fix that ?
I use MySQL DB.

Thanks in advance for your help


Top
 Profile  
 
 Post subject: Re: SQL Query generated by Hibernate
PostPosted: Fri Sep 28, 2012 8:28 am 
Newbie

Joined: Thu Sep 27, 2012 12:12 pm
Posts: 3
I found a solution to by-pass the problem but not resolve it!
it Consists to modify inheritance strategy, from TABLE_PER_CLASS to JOINED.
With JOINED strategy each class (even the abstract class) has a table in DB, thereby, when hibernate makes a count query, it doesn't request on an union between subclasses tables but request the table that represent the abstract class.

This a by-pass solution, but not a resolution of my problem if you have an idea, please make a reply.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.