-->
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: Criteria: Query on associated collections
PostPosted: Mon Aug 07, 2006 5:40 am 
Newbie

Joined: Fri Aug 04, 2006 9:18 am
Posts: 1
Hi,

i am currently searching for a solution of a problem with the Criteria API of Hibernate 3.2:

I have the following mapping:
Class A references a Set of class B.
Class B is an abstract class and has different extensions (B1, B2, ...). The inheritance is mapped via joined subclass using a discriminator.
All extensions of class B contain different properties.
The mapping of the abstract class B contains a property which references the discriminator column.

My problem:
I want to query all instances of class A which reference an instance of class B1 with the property B1.P1 set to "foo".

My current approach:
Code:
Criteria criteria = session.createCriteria(A.class);
Criteria subCriteria = criteria.createCriteria("setOfBs");
subCriteria.add(
    Restrictions.and(
        Restrictions.eq("discriminator", "B1"),
        Restrictions.eq("P1", "foo")
    )
);
criteria.list();


This criteria results in a SQL Exception:
Code:
org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
   at ...
Caused by: java.sql.SQLException: ORA-00904: "B_REF1_1_"."FOO": invalid identifier
   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
   at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
   at ...


This exception is is thrown because hibernate creates a wrong select statement:

Code:
select
        this_.a_id as a1_3_1_,
        b_ref1_.b_id as a1_0_0_,
        b_ref1_.discriminator as a2_0_0_,
        b_ref1_.a_id as a3_0_0_,
        b_ref1_1_.bar as a2_7_0_,
        b_ref1_2_.foo as a2_8_0_,
        b_ref1_3_.fnord as a2_9_0_,
    from
        t_a this_
    inner join
        t_b b_ref1_
            on this_.a_id=b_ref1_.a_id
    left outer join
        t_b_1 b_ref1_1_
            on b_ref1_.b_id=b_ref1_1_.b_id
    left outer join
        t_b_2 b_ref1_2_
            on b_ref1_.b_id=b_ref1_2_.b_id
    left outer join
        t_b_3 b_ref1_3_
            on b_ref1_.b_id=b_ref1_3_.b_id
    where
        (
            b_ref1_.discriminator=?
            and b_ref1_1_.foo=?
        )


It would be correct if the where clause would look like that
Code:
    where b_ref1_[b]2[/b]_.foo=?


Is there any possibility for a query on properties of references objects in a inhertiance hierachy using the criteria API?

Thanks in advance
i.


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.