-->
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.  [ 15 posts ] 
Author Message
 Post subject: polymorphic persistence
PostPosted: Mon Oct 27, 2003 11:16 am 
Beginner
Beginner

Joined: Wed Oct 22, 2003 11:26 am
Posts: 31
I am trying to map a class and sublass but when i try to build session factory it gives :

net.sf.hibernate.MappingException: discriminator mapping required for polymorphic persistence
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:683)
at net.sf.hibernate.persister.PersisterFactory.create(PersisterFactory.java:29)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:207)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:627)

I am mapping subclass as :
<subclass name="com.bunge.bgm.contract.business.domain.period.AccountingPeriod">
<property name="_isClosed" column="OPEN_CLOSE"/>
<property name="_isOpen" column="OPEN_CLOSE"/>
</subclass>

How to give mapping for polymorphic persistence ? It is still not clear from the stack trace. I tried to find an example but didnt get. Please help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 11:51 am 
Beginner
Beginner

Joined: Wed Oct 22, 2003 11:26 am
Posts: 31
this is the class where exception is thrown.

10:47:06,627 INFO ReflectHelper:328 - reflection optimizer disabled for: com.bunge.bgm.contract.business.domain.period.Period, InvocationTargetException: null

I am having a Super and Subclass and subclass is mapped but while creating session factory the exception is thorwn.
Can i find a sample example implementing SUper and Subclass relationship ?
Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 12:25 pm 
Regular
Regular

Joined: Mon Sep 08, 2003 4:53 am
Posts: 70
Location: Germany
What Hibernate version you are using? I had expected another MappingException, cause you are using the column OPEN_CLOSE in two different properties.


Top
 Profile  
 
 Post subject: Re: polymorphic persistence
PostPosted: Mon Oct 27, 2003 12:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
rajanvashisht wrote:
<subclass name="com.bunge.bgm.contract.business.domain.period.AccountingPeriod">


You need to add a discriminator-value attribute to your subclass AND and discriminator tag to your master class.

Have a look at section 4.1 of hibernate reference guide.

When your mapping will be corrected, the next error will be the one andread points to you : you cannot map 2 read/write properties on the same column

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 12:45 pm 
Beginner
Beginner

Joined: Wed Oct 22, 2003 11:26 am
Posts: 31
i m using HIbernate2.0.3 and it works this way :
<property name="_isClosed" column="OPEN_CLOSE" insert="false" update="false"/>
<property name="_isOpen" column="OPEN_CLOSE" insert="false" update="false"/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I think it will work then.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 12:57 pm 
Beginner
Beginner

Joined: Wed Oct 22, 2003 11:26 am
Posts: 31
Thanks for the information. I added discriminator-value attribute to subclass and discriminator element for super class and then the discriminator mapping problem is solved. Thanks once again.


Top
 Profile  
 
 Post subject: Isn't this a bug then?
PostPosted: Tue Dec 09, 2003 6:03 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 5:59 pm
Posts: 25
Location: Los Angeles
This info shouldn't be required according to the hibernate docs. Is this a bug?

From the overview doc:
discriminator-value (optional - defaults to the class name): A value that distiguishes individual subclasses.

From the DTD:
<!ELEMENT discriminator (column?)>
<!ATTLIST discriminator column CDATA #IMPLIED> <!-- default: "class"|none -->
...
<!ATTLIST subclass discriminator-value CDATA #IMPLIED> <!-- default: unqualified class name | none -->


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 8:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The <discriminator> element is required if the <class> has <subclass>es. The discriminator-value attribute is always optional.


Top
 Profile  
 
 Post subject: discriminator required
PostPosted: Fri Feb 27, 2004 5:05 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
It would be helpful if the docs stated this little bit of info.

It didn't cost me much time;because I found this post; but I interpreted the docs that it was optional as well. Rather than optional EXCEPT when actually subclassed.

Troy


Top
 Profile  
 
 Post subject: still getting error
PostPosted: Fri Feb 27, 2004 5:44 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
OK I have tried this 2 ways and I STILL get the error:

discriminator mapping required for polymorphic persistence

net.sf.hibernate.MappingException: discriminator mapping required for polymorphic persistence at net.sf.hibernate.persister.EntityPersister.(EntityPersister.java:733) at net.sf.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:41) at net.sf.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:137) at net.sf.hibernate.cfg.Configuration.buildSessionFactory


Here was my last attempt. (all in base class mapping file)
I also tried to put the subclass in its own xml.

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

<hibernate-mapping>

<class name="com.poc2.model.hibernate.staffing.StaffingOrder"
table="StaffingOrder"
discriminator-value="StaffingOrder"
>

<meta attribute="class-description" inherit="false">
@hibernate.class
table="StaffingOrder"
discriminator-value="StaffingOrder"
</meta>

<id
name="staffingOrderId"
type="java.lang.String"
column="staffingOrderId"
>
<meta attribute="field-description">
@hibernate.id
generator-class="assigned"
type="java.lang.String"
column="staffingOrderId"

</meta>
<generator class="net.sf.hibernate.id.SQLServerGUIDGenerator" />
</id>


<property
name="requiredResponseDate"
type="java.sql.Timestamp"
column="requiredResponseDate"
length="23"
>
<meta attribute="field-description">
@hibernate.property
column="requiredResponseDate"
length="23"
</meta>
</property>
<property
name="multiVendorDistribution"
type="boolean"
column="multiVendorDistribution"
not-null="true"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="multiVendorDistribution"
length="1"
not-null="true"
</meta>
</property>
<property
name="userArea"
type="java.lang.String"
column="userArea"
length="2000"
>
<meta attribute="field-description">
@hibernate.property
column="userArea"
length="2000"
</meta>
</property>
<property
name="positionQuantity"
type="java.lang.Integer"
column="positionQuantity"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="positionQuantity"
length="10"
</meta>
</property>
<property
name="positionQuanityOpen"
type="java.lang.Integer"
column="positionQuanityOpen"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="positionQuanityOpen"
length="10"
</meta>
</property>
<property
name="createdOn"
type="java.sql.Timestamp"
column="createdOn"
length="23"
>
<meta attribute="field-description">
@hibernate.property
column="createdOn"
length="23"
</meta>
</property>
<property
name="createdBy"
type="java.lang.String"
column="createdBy"
length="64"
>
<meta attribute="field-description">
@hibernate.property
column="createdBy"
length="64"
</meta>
</property>
<property
name="lastUpdatedOn"
type="java.sql.Timestamp"
column="lastUpdatedOn"
length="23"
>
<meta attribute="field-description">
@hibernate.property
column="lastUpdatedOn"
length="23"
</meta>
</property>
<property
name="lastUpdatedBy"
type="java.lang.String"
column="lastUpdatedBy"
length="64"
>
<meta attribute="field-description">
@hibernate.property
column="lastUpdatedBy"
length="64"
</meta>
</property>

<!-- associations -->
<!-- bi-directional many-to-one association to OrderType -->
<many-to-one
name="orderType"
class="com.poc2.model.hibernate.staffing.OrderType"
not-null="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="orderType"
</meta>
<column name="orderType" />
</many-to-one>

<!-- bi-directional many-to-one association to OrderStatus -->
<many-to-one
name="orderStatus"
class="com.poc2.model.hibernate.staffing.OrderStatus"
not-null="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="orderStatus"
</meta>
<column name="orderStatus" />
</many-to-one>





<subclass name="com.poc2.view.struts.wrapper.staffing.JobOffer"
discriminator-value="JobOffer"
>
<property name="actionFlag" type="string"/>
</subclass>

</class>
</hibernate-mapping>




What am I doing wrong now?

I am trying to use my


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 12:13 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Add the <discriminator> element in the master class. As per the doc and gavin's answer.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: reply
PostPosted: Mon Mar 01, 2004 3:25 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
The xml above IS the master class.
It does have the discriminator element.

Unless I misinterpret.

Troy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 6:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
dude, there is no <discriminator> in your mapping, only a discriminator-value

_________________
Emmanuel


Top
 Profile  
 
 Post subject: sorry
PostPosted: Wed Mar 03, 2004 6:51 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
emmanuel wrote:
dude, there is no <discriminator> in your mapping, only a discriminator-value


Yes I realized that. Should have followed up this post. Sorry


Thanks


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