-->
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: Polymorphic queries, attribute of subclass via superclass
PostPosted: Fri Jul 16, 2004 4:29 pm 
Newbie

Joined: Thu Jul 08, 2004 6:39 pm
Posts: 1
Suppose I have the following class relationship.

public class Plane
{
int wings; // number of wings.
// etc.
}

public class JetPlane
{
int numPilots;
String model;
// etc.
}

I now do this.

List results = session.createCriteria(Plane.class)
.add(Expression.eq("model", "AirBus");

I get this.

1) testPlanesByCriteria2(com.ap.ApTest)java.lang.NullPointerException
at net.sf.hibernate.persister.NormalizedEntityPersister.toColumns(NormalizedEntityPersister.java:1099)
at net.sf.hibernate.expression.AbstractCriterion.getColumns(AbstractCriterion.java:35)
at net.sf.hibernate.expression.SimpleExpression.toSqlString(SimpleExpression.java:40)
at net.sf.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:66)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3591)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at com.ap.ApTest.testPlanesByCriteria2(ApTest.java:305)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22)
at junit.extensions.TestSetup$1.protect(TestSetup.java:19)
at junit.extensions.TestSetup.run(TestSetup.java:23)
at com.ap.ApTest.main(ApTest.java:29)

My mapping file looks like this.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<class name="com.ap.Plane" table="planes" discriminator-value="N"
polymorphism="implicit">
<id name="id">
<generator class="native"/>
</id>
<property name="wings" column="`wings`" not-null="true"/>
<joined-subclass name="com.ap.JetPlane">
<key column="JetPlanes"/>
<property name="numPilots" column="`npilots`" not-null="true"/>
<property name="model" column="`model`" not-null="true"/>
</joined-subclass>
</class>
</hibernate-mapping>

Can somebody please tell me if Hibernate is supposed to be able to
handle this case? Yes, I know that 'model' is not a property of
'Plane'. I believe I understand some of the difficulties, however
the mapping file does contain global information about all subclasses
of Plane.

Many thanks,
--
Ravi/


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.