-->
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.  [ 5 posts ] 
Author Message
 Post subject: Inserting a subclass, but want to retrive it as the supercla
PostPosted: Tue Oct 26, 2004 8:59 am 
Newbie

Joined: Tue Oct 26, 2004 8:51 am
Posts: 2
Hi,

I have created a table containing two types of objects: BatchInfo and Batch objects. The Batch class is a subclass of BatchInfo.

I want to insert a Batch object into the table, and thereafter retreive it as a BatchInfo object. Is it possible ?
Thanks.

My xml file:
--------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>


<class name="BatchInfo" table="batch">
<id name="id" column="id" type="long">
<generator class="sequence">
<param name="sequence">batch_sequence</param>
</generator>
</id>
<discriminator column="subclass"/>
<property name="owner" column="owner"/>
<property name="name" column="name"/>
<property name="description" column="description"/>
<property name="format" column="format"/>
<property name="timeEstimate" column="timeEstimate"/>
<property name="lastUsedDate" column="lastUsedDate"/>
<property name="createdDate" column="createdDate"/>

<subclass name="Batch" discriminator-value="batch" >

<property name="samples" column="samples"/>
</subclass>
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 10:20 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
yes, see 11.6. Polymorphic queries


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 3:22 pm 
Newbie

Joined: Tue Oct 26, 2004 8:51 am
Posts: 2
adcworks wrote:
yes, see 11.6. Polymorphic queries


Yes,

But it will return a list of instances of the Batch class and not instances of the BatchInfo class.

I want to be able to get a list of BatchInfo objects, which are build from the Batch objects in the table.

/Lorenzen


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 4:41 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
well just query "from Batch" and your result is automatically a BatchInfo because it extends it!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 5:06 pm 
Regular
Regular

Joined: Tue Sep 28, 2004 6:34 pm
Posts: 50
Afaik Hibernate 2.xx does not handle loading lightweight version of heavyweight object.


Did you try using native query?

Query sqlQuery = session.createSQLQuery(
"select {bi.*} from batch {bi}",
"bi",
BatchInfo.class);
sqlQuery.list();


try it and let us know if it works.

Are you expecting to have instances of BatchInfo or it is going to be sort of abstract class?

Lukasz


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