-->
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: Inherited variable is referenced by child table alias
PostPosted: Fri Nov 18, 2005 5:19 pm 
Beginner
Beginner

Joined: Tue Feb 01, 2005 5:26 pm
Posts: 24
Location: dallas
Hibernate version:
Hibernate version no 3.0


Inherited variable is referenced by child table alias in hibernate generated sql when used in where clause of a set tag to filter the collection. Here the variable 'IS_DELETED' is referenced by child table alias 'cats0_' rather than parent alias 'cats0_1_'.
Is it a bug or expected behavior of hibernate. Is there a workarround for this. Or instead i can hardcode in where clause where="cats0_.IS_DELETED=0"

Mapping documents:
Code:
<?xml version="1.0"?>
<!-- $Id: Entity.hbm.xml,v 1.24 2005/11/11 20:08:42 vpajjuri Exp $ -->
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
   <class name="com.test.services.person.LivingEntity"
      table="LIVING_ENTITY">
      <cache usage="transactional" />
      <id name="UUID"
         type="com.test.services.util.hibernate.UUIDVarcharType"
         column="UUID">
         <generator class="assigned" />
      </id>
      <property name="deleted" column="IS_DELETED" not-null="true" />
      <joined-subclass name="com.test.services.person.Person"
         table="PERSON" >
         <key column="PERSON_UUID" />
         <property name="firstName" column="FIRST_NAME"
            not-null="true" />

         <set name="cats" inverse="true" cascade="all" where="IS_DELETED=0" >
            <cache usage="transactional" />
            <key column="CAT_UUID" />
            <one-to-many class="com.test.services.person.Cat" />
         </set>
      </joined-subclass>
      <joined-subclass name="com.test.services.person.Cat"
         table="CAT">
         <key column="CAT_UUID" />
         <property name="personUUID" column="PERSON_UUID"
            insert="false" update="false"
            type="com.test.services.util.hibernate.UUIDVarcharType" />
         <property name="catName" column="CAT_NAME" />
         <many-to-one name="person" class="com.test.services.person.Person"
            column="PERSON_UUID" not-null="true" />
      </joined-subclass>
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
Person p=new Person();
        Cat c=new Cat();
        p.setFirstName("vamshi");
        c.setCatName("Jelly");
        //c.setDeleted(true);
        p.addCat(c);
        Session s=HibernateUtil.currentSession();
        org.hibernate.Transaction tx=s.beginTransaction();
        s.save(p);
        tx.commit();
        HibernateUtil.closeSession();
        for(int i=0;i<10;i++){
            Session s1=HibernateUtil.currentSession();
            org.hibernate.Transaction tx1=s1.beginTransaction();
            Person p1=(Person)s1.get(Person.class,p.getUUID());
            p1.getCats();
            tx1.commit();
            HibernateUtil.closeSession();
        }
        Session s2=HibernateUtil.currentSession();
        org.hibernate.Transaction tx2=s2.beginTransaction();
        s2.delete(p);
        tx2.commit();
        HibernateUtil.closeSession();

Full stack trace of any exception that occurs:
Code:
[color=red][11-18-05 14:52:44](W)<497>[JDBCExceptionReporter         ]{10} SQL Error: 904, SQLState: 42000
[11-18-05 14:52:44](S)<498>[JDBCExceptionReporter         ]{10} ORA-00904: "CATS0_"."IS_DELETED": invalid identifier

[11-18-05 14:52:44](I)<499>[DefaultLoadEventListener      ]{10} Error performing load command
StackTrace:
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.test.services.person.Person.setCats
   at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:203)
   at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
   at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
   at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
   at org.hibernate.loader.Loader.doQuery(Loader.java:436)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
   at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:151)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:621)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:614)
   at tests.com.test.services.db.telemetrydevice.TestJbossTreeCache.testJbossTreecache(TestJbossTreeCache.java:145)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: net.sf.cglib.beans.BulkBeanException: could not initialize a collection: [com.test.services.person.Person.cats#5744507C935F474B82A9C0FD7B20AC93]
   at com.test.services.person.Person$$BulkBeanByCGLIB$$d97fa72d.setPropertyValues(<generated>)
   at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
   ... 33 more
Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.test.services.person.Person.cats#5744507C935F474B82A9C0FD7B20AC93]
   at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.loader.Loader.loadCollection(Loader.java:1441)
   at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
   at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:176)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
   at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:134)
   at com.test.services.person.Person.setCats(Person.java:58)
   ... 35 more
Caused by: java.sql.SQLException: ORA-00904: "CATS0_"."IS_DELETED": invalid identifier

   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
   at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
   at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
   at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:626)
   at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:182)
   at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:500)
   at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:942)
   at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:532)
   at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1037)
   at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2905)
   at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2946)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
   at org.hibernate.loader.Loader.doQuery(Loader.java:391)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
   at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
   ... 43 more[/color]

Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):
Hibernate: select person0_.PERSON_UUID as UUID0_, person0_1_.IS_DELETED as IS2_40_0_, person0_.FIRST_NAME as FIRST2_41_0_ from PERSON person0_ inner join LIVING_ENTITY person0_1_ on person0_.PERSON_UUID=person0_1_.UUID where person0_.PERSON_UUID=?
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as UUID1_, cats0_1_.IS_DELETED as IS2_40_1_, cats0_.PERSON_UUID as PERSON2_42_1_, cats0_.CAT_NAME as CAT3_42_1_, person1_.PERSON_UUID as UUID0_, person1_1_.IS_DELETED as IS2_40_0_, person1_.FIRST_NAME as FIRST2_41_0_ from CAT cats0_ inner join LIVING_ENTITY cats0_1_ on cats0_.CAT_UUID=cats0_1_.UUID inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID left outer join LIVING_ENTITY person1_1_ on person1_.PERSON_UUID=person1_1_.UUID where cats0_.IS_DELETED=0 and cats0_.CAT_UUID=?

Debug level Hibernate log excerpt:

Code:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 6:31 pm 
Newbie

Joined: Mon Dec 05, 2005 5:34 pm
Posts: 3
Location: Cincinnati, OH
I have encountered the same problem, although I'm using Criteria queries. Any way to access the generated aliases for super classes?


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.