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: Using discriminator in a hibernate Query / problems
PostPosted: Thu Jan 04, 2007 10:43 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0
Mapping documents:
<hibernate-mapping>
<class discriminator-value="-1" table="transferrecord" name="com.mm.mw.dto.TransferRecordImpl">
<id unsaved-value="0" name="recordNumber" column="id">
<generator class="increment"/>
</id>
<discriminator type="int" column="interfaceType"/>
<property name="creationTimestamp"/>
<property name="status"/>
<property name="dlfSiteRef"/>
<property name="transmissionNumber"/>
<property name="transmissionTimestamp"/>
<property name="interfaceType" column="interfaceType" update="false" insert="false"/>
<subclass name="com.mm.mw.ExpectedReceipt" discriminator-value="2">
<property name="cofcref"/>
<property name="locationRef"/>
<property name="ticket"/>
<property name="quantity"/>
<property name="partNumber"/>
</subclass>
<subclass name="com.mm.mw.ReceiptConfirmation" discriminator-value="1">
<property name="cofcref"/>
<property name="locationRef"/>
<property name="manualInd"/>
<property name="productRef"/>
<property name="receiptRef"/>
<property name="operatorRef"/>
<property name="scanner"/>
<property name="ticket"/>
</subclass>
<subclass name="com.mm.mw..ReplenRequest" discriminator-value="0">
<property name="valid"/>
<property name="manualInd"/>
<property name="operatorRef"/>
<property name="productRef"/>
<property name="locationRef"/>
<property name="scanDate"/>
<property name="scanTime"/>
<property name="scanner"/>
<property name="stockOutInd"/>
</subclass>
</class>
</hibernate-mapping>

-------
Hi all,
i have the following problem

as you can see from mapping document, i have TransferRecordImpl class which is extended by other 3 classes, ReplenRequest, ExpReceipt and ReceiptConfirmation.

I choosed to use a discriminator to differentiate the three....
Unfortunatley, due to my usecase, the discrimnator must be a property of
my class, for the very simple reason that one usecase of my app says
'findByInterfaceType'
where the client supplies the int value of the interfaceType.. and i could look it up by using a findByInterfaceType.

i have test failing because, after inserting a TransferRecord, using a query
like findByInterfaceType(0) didnt return anything.... and after struggling i realized that mayb the problem is this

<property name="interfaceType" column="interfaceType" update="false" insert="false"/>

But i need to do a search based on the discriminator..... and i want to avoid the '
if(value =1)
then findExpreceipt
and so on..

is that possible then to use a discriminator in a query?

if not, how can i fix my problem? shall i change mapping strategy?

thanks and regards
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 1:16 pm 
Regular
Regular

Joined: Thu Aug 17, 2006 4:50 am
Posts: 55
Location: Mallorca
why do you have the insert="false" update="false"?

have you checked that correct values are stored in the database?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 2:49 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
hello,
thanx for reply
i had to do that way because while loading up applicationContext, i was receiving error because my discriminator was also a column of the database..
after reading docs, (discriminator is a 'convenient' field between hibernate and db, according to docs, so i shouldn't be the one who set it or update it)..
i think i'd need to move to a different approach, suchas tabe x subclass hierarchy...

any comments will be welcomed

thanx and regards
marco


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.