-->
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.  [ 3 posts ] 
Author Message
 Post subject: left join of collection results in generic java.lang.Object
PostPosted: Fri Feb 27, 2004 9:46 am 
Newbie

Joined: Tue Sep 16, 2003 11:30 am
Posts: 2
Hello,

I'm using Hibernate 2.1.2/MySQL 3.26 for a Tibetan Dictionary application and now I am struggling with an HQL query that joins a collection but returns objects of class java.lang.Object that are of course not castable to any mapped subclass.

I'm trying to set constraints in the where clause based on values of objects in an indexed collection. I've solved all previous Hibernate problems with the FAQs, docs and forum searches but I'm stuck here. I'm concerned that it might be an issue with my mapping design. where the meta component is actually a property of the superclass of Term and Pronunciation, (LexComponent).

Here's my query:

Code:
from org.thdl.lex.component.Term as term
left join term.pronunciations as pronunciation
where term.meta.createdBy = 10
or pronunciation.meta.createdBy = 10


I can see in the Hibernate log that a Term and Pronunciation are correctly hydrated but I get a ClassCastException when I try to cast to ITerm or Term because the class is a plain old java.lang.Object. Any ideas would be greatly appreciated. If I remove the join (and the reference to it in where clause) the cast test passes.

The relevant portion of the mapping is:

Code:
<class name="org.thdl.lex.component.LexComponent" proxy="org.thdl.lex.component.ILexComponent" table="Meta">

<id name="metaId" type="java.lang.Integer" column="metaId"></id>

<joined-subclass name="org.thdl.lex.component.Term" proxy="org.thdl.lex.component.ITerm" table="Terms">

<key column="metaId"/>

<property name="term" type="java.lang.String" column="term" not-null="true" length="255"/>

<list name="pronunciations" table="Pronunciations" lazy="true">

<key column="parentId"/>

<index column="index"/>

<one-to-many class="org.thdl.lex.component.Pronunciation"/>

</list>

</joined-subclass>

<joined-subclass name="org.thdl.lex.component.Pronunciation" proxy="org.thdl.lex.component.IPronunciation" table="Pronunciations">

<key column="metaId"/>

<property name="parentId" type="java.lang.Integer" column="parentId" length="11"/>

<many-to-one name="parent" class="org.thdl.lex.component.LexComponent" column="parentId" insert="false" update="false"/>

<property name="phonetics" type="java.lang.String" column="phonetics" not-null="true" length="65535"/>

<property name="phoneticsType" type="java.lang.Integer" column="phoneticsType" not-null="true" length="6"/>

</joined-subclass>

<component name="meta" class="org.thdl.lex.component.Meta">
<property name="createdBy" type="java.lang.Integer" column="createdBy" not-null="true" length="11"/>
</component>


</class>



The java code is:

Code:
Query query = null;
Iterator it = null;
List terms;

String queryString = "from "
+ "org.thdl.lex.component.Term as term "
+ " left join term.pronunciations as pron "
+ " where term.meta.createdBy = :createdBy"
+ " or pron.meta.createdBy = :createdBy";

try
{
query = getSession().createQuery( queryString );
query.setInteger( "createdBy", 10 );
terms query.iterate();
terms=new LinkedList();
while (iterator.hasNext() )
{
terms.add( iterator.next() );
}
}
catch ( HibernateException he )
{
throw new LexRepositoryException( he );
}
return terms;



Here's the tail end of my unit test which includes the debug log of my seemingly succesful query. The assertion failed is just a class cast to ITerm. But casting to Term also fails

Code:
[java]  08:29:43,365 DEBUG Loader:215 - total objects hydrated: 2
[java]  08:29:43,380 DEBUG SessionImpl:2179 - resolving associations for [org.thdl.lex.component.Term#1]
[java]  08:29:43,416 DEBUG SessionImpl:2201 - done materializing entity [org.thdl.lex.component.Term#1]
[java]  08:29:43,432 DEBUG SessionImpl:2179 - resolving associations for [org.thdl.lex.component.Pronunciation#76]
[java]  08:29:43,434 DEBUG SessionImpl:1972 - loading [org.thdl.lex.component.LexComponent#1]
[java]  08:29:43,439 DEBUG SessionImpl:2068 - attempting to resolve [org.thdl.lex.component.LexComponent#1]
[java]  08:29:43,441 DEBUG SessionImpl:2083 - resolved object in session cache [org.thdl.lex.component.LexComponent#1]
[java]  08:29:43,446 DEBUG SessionImpl:2201 - done materializing entity [org.thdl.lex.component.Pronunciation#76]
[java]  08:29:43,456 DEBUG JDBCTransaction:73 - rollback
[java]  08:29:43,463 DEBUG SessionImpl:505 - transaction completion
[java]  There are 1 terms matching your query.
[java] Object is of class name: [Ljava.lang.Object;
[java] F
[java] Time: 31.912
[java] There was 1 failure:
[java] 1) testFindTermsByMeta(org.thdl.lex.LexComponentRepositoryTest)junit.framework.AssertionFailedError
[java]     at org.thdl.lex.LexComponentRepositoryTest.testFindTermsByMeta(LexComponentRepositoryTest.java:85)
[java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java]     at org.thdl.lex.TestAll.main(TestAll.java:22)

[java] FAILURES!!!
[java] Tests run: 1,  Failures: 1,  Errors: 0


Thanks so much for any insights here.

Sincerely,
Travis McCauley
Toronto, ON


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 9:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use "select term from ...." if you want only the term, otherwise you will get a List of Object[2]s, containing term and the joined object.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 10:04 am 
Newbie

Joined: Tue Sep 16, 2003 11:30 am
Posts: 2
That works. Thanks!

-Travis


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