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: per-hierarchy mapping causes queries to not return vals.
PostPosted: Sun Aug 13, 2006 8:27 am 

Joined: Sun Apr 09, 2006 8:38 am
Posts: 14
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: \

Mapping documents:
<hibernate-mapping auto-import="false" default-access="com.pontis.platform.tgp.persistence.hibernate.PropertyBridge" default-cascade="none" default-lazy="true">
<class name="com.pontis.app.general.AppReference" table="APPREFERENCE" lazy="false" select-before-update="false" dynamic-update="false" dynamic-insert="false" discriminator-value="com.pontis.app.general.AppReference" >
<cache usage="read-write" />
<id type="java.lang.String" column="id" name="id">
<generator class="assigned" />
<discriminator type="string" force="false" insert="true"
column="my_discriminator" />
<version name="version" column="version"
<hibernate-mapping auto-import="false" default-cascade="none" default-lazy="true">
<subclass name="com.pontis.app.subscriber.SubscriberValue" extends="com.pontis.app.general.AppReference" lazy="false" select-before-update="false" discriminator-value="com.pontis.app.subscriber.SubscriberValue" />

Code between sessionFactory.openSession() and session.close():

getHibernateTemplate().find("From com.pontis.app.subscriber.SubscriberValue
where refcode="123");
Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):
Hibernate: select subscriber0_.id as id25_, subscriber0_.version as version25_, subscriber0_.lifeCycleState as lifeCycl4_25_, subscriber0_.creator as creator25_, subscriber0_.lastModifiedBy as lastModi6_25_, subscriber0_.availableFlag as availabl7_25_, subscriber0_.creationDate as creation8_25_, subscriber0_.lastModifiedDate as lastModi9_25_, subscriber0_.refCode as refCode25_, subscriber0_.refCodeDisplayString as refCode11_25_ from APPREFERENCE subscriber0_ where 1=2 and subscriber0_.refCode=?
Debug level Hibernate log excerpt:

I have a class, and a subclass. they are mapped onto the same table.
I am able to insert values of the sublcass through hibernate fine, but trying to perform a queryt on the subclass generates the above SQL that has a condition "where 1=2" - something that indicates that hiberate thinks it shouldn't return the results.

One more thing - the class (not subclass) extends a different class, which is not mapped at all.
so we have
SomeAbstractClass (not mapped)
AppReference(mapped as <class>)
SubscriberValue(mapped as <subclass>)

if I try to map the same classes using a table per subclass approach - all is well.

Any idea?


 Post subject: a small addition
PostPosted: Mon Aug 14, 2006 2:40 am 

Joined: Sun Apr 09, 2006 8:38 am
Posts: 14
if I try and use spring's load (instead of find[=query]) on the instances of the subclass, it works fine -
meaning I can call load(SubscriberValue.class, "123"), and I get the instance.

but if I try the query "From com.pontis.app.subscriber.SubscriberValue
where refcode="123", the results are null and the SQL contains where 1=2.


 Post subject:
PostPosted: Wed Aug 23, 2006 4:32 am 

Joined: Sun Apr 09, 2006 8:38 am
Posts: 14
Problem solved.

The mapped classes are actually interfaces.
I implemented an interceptor that takes care of the instantiation myself.

When hibernate mapps my classes (interfaces), it decides that they are abstract (since they are pojos+interfaces).

The interceptor is the part that actually makes sure that hibernate instantiates my objects, despite the fact that they are abstract.

When hibernate mapps the classes that belong to the per-hierarchy mapping,
it checks for abstract, and if the class is abstract, hibernate doesn't prepare the selects for them properly.

Basically, the solution was to tell hibernateabstract=false in the hbms.


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.