-->
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.  [ 9 posts ] 
Author Message
 Post subject: Returning an Interface as a property type, how to map?
PostPosted: Thu Oct 23, 2003 2:46 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
Hi,

We have a existing object design that I am trying to map in Hibernate. Here is the jist.

Class Buyer is an Interface, and one implementing class is BuyerData:

<class name="data.partnership.Buyer" table="BUYER_SETUP">

<id column="BUYER_ID" name="id" type="java.lang.Long" unsaved-value="null">
<generator class="util.hibernate.SequenceIntervalGenerator">
<param name="sequence">SEQ_BUYER_ID</param>
<param name="interval">1</param>
</generator>
</id>

<subclass name="com.notiva.cbo.buyer.data.partnership.BuyerData">

<property column="BUYER_COLLAB_UID_TXT" name="buyerUid" type="java.lang.String"/>
....
</subclass>
</class>

We have another class that needs to return the Interface:

<class name="data.partnership.SellerPartnershipData" table="SELLER_PARTNERSHIP_SETUP">

<id column="SELLER_PARTNERSHIP_ID" name="id" type="java.lang.Long" unsaved-value="null">
<generator class="com.notiva.util.hibernate.SequenceIntervalGenerator">
<param name="sequence">SEQ_SELLER_PARTNERSHIP_ID</param>
<param name="interval">1</param>
</generator>
</id>

<property column="BUYER_ID" name="buyer" type="data.partnership.Buyer"/>
...
</class>

This is the Java file:

public class SellerPartnershipData extends AbstractSeller
implements Partnership, Effective {

public Buyer getBuyer() {
return null;
}
....
}



But during startup, the hibernate session factory errors out on the latter mapping file with this error:

13:37:13,968 ERROR [Configuration] Could not compile the mapping document
net.sf.hibernate.MappingException: Could not interpret type: com.notiva.core.data.partnership.BuyerData

Any ideas? thanks.

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 3:00 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
How are com.notiva.cbo.buyer.data.partnership.BuyerData and com.notiva.core.data.partnership.BuyerData related?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 3:08 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
Well, I truncated the package names for readability, but here they are fully qualified:

com.notiva.cbo.buyer.data.partnership.BuyerData

implements

com.notiva.core.data.partnership.Buyer


...and this class:

com.notiva.cbo.buyer.data.partnership.SellerPartnershipData

has this method:

public Buyer getBuyer() {
return null;
}



I just want to be able to return an Interface in the mapping. Thanks.

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 3:18 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
I think for a class type to be mentioned as a many-to-one type, that class also has to be a Hibernate mapped class. So somewhere you'd have to have

Code:
<class
      name="com.notiva.core.data.partnership.Buyer">

and have com.notiva.cbo.buyer.data.partnership.BuyerData and other implementing classes as <subclass>s of that class.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 3:31 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
cutie wrote:
I think for a class type to be mentioned as a many-to-one type, that class also has to be a Hibernate mapped class. So somewhere you'd have to have

Code:
<class
      name="com.notiva.core.data.partnership.Buyer">


and have com.notiva.cbo.buyer.data.partnership.BuyerData and other implementing classes as <subclass>s of that class.



I thought I did that.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 4:26 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
oh sorry, I got confused with your truncated class names. then I'm not sure what's going on


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 5:06 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
I think I might have figured out what my problem is. Our interface (Buyer) is really the only subclass, so there is no discriminator value (dont ask why it is only subclass). So if I strip id down to just trying to load that mapping, I get:

Code:
net.sf.hibernate.MappingException: discriminator mapping required for polymorphic persistence


..so I think my only solution is to add a default discriminator column, or not use the interface.

matt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 5:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Looks like you don't need to map the interface at all. You -do- realise that the declared type of the property does -not- need to match the type declared in the <many-to-one> element, right?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 11:07 am 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
gavin wrote:
Looks like you don't need to map the interface at all. You -do- realise that the declared type of the property does -not- need to match the type declared in the <many-to-one> element, right?



Here's my penance:

Instead of <many-to-ones.. we have used <properties and it seems to have worked in the past, but it did not work in this case. Maybe the <property tag has stronger inspection and didn't like the subclass, whatever... but when we used the (proper) <many-to-one it worked.

Thanks,

Matt


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