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: Error on table-per-subclass, need help
PostPosted: Wed Dec 24, 2003 9:27 pm 
Newbie

Joined: Wed Dec 24, 2003 9:17 pm
Posts: 6
Exception:
net.sf.hibernate.WrongClassException: Object with id: 60388287-8fe7-4b11-b820-3d728e8d8466 was not of the specified subclass: gov.gdgs.enterprise.Enterprise (Discriminator: 1100 )

enterprise.hbm.xml:
<class name="Enterprise" table="MarketEntity">
<id name="entityNo" column="entityNo" type="string" length="36">
<generator class="assigned"/>
</id>
<discriminator type="string" column="entityTypeID" length="4"/>
<property name="registerNo" column="registerNo" type="string" length="30"/>
<property name="corpName" column="corpName" type="string" length="100"/>
<property name="businessScope" column="businessScope" type="string" length="800"/>
<property name="entityTypeID" column="entityTypeID" type="string" length="4" insert="false" update="false"/>
<subclass name="Company" discriminator-value="1100" >
<bag name="corpInvestor" lazy="false" inverse="true" cascade="all">
<key column="entityNo"/>
<one-to-many class="CorpInvestor"/>
</bag>
</subclass>
</class>

<class name="CorpInvestor" table="corpInvestor" >
<id name="corpInvestorID" column="corpInvestorID" type="string" length="36">
<generator class="assigned"/>
</id>
<property name="entityNo" column="entityNo" type="string" length="36"/>
<property name="investorName" column="investorName" type="string" length="100"/>
<property name="address" column="address" type="string" length="100"/>
</class>

EnterpriseTest.java:
public void testEnterprise() throws HibernateException {
Session session = factory.openSession();
List list = session.createCriteria( Enterprise.class )
.add( Expression.like( "corpName" , "%电子%" ) )
.add( Expression.eq( "entityTypeID" , "1100" ) .setMaxResults( 10 )
.list();

System.out.println( "Result counts : " + list.size() );
for ( int i = 0 ; i < list.size() ; i ++ ) {
Enterprise enterprise = ( Enterprise ) list.get( i );
System.out.println( "Enterprise is : " + enterprise.toString() );
if ( enterprise instanceof Company ) {
System.out.println( enterprise.toString() );
}
}
session.close();
}

I have traced into the EntityPersister, there are two items in subclassesByDiscriminatorValue as the following:
key="gov.gdgs.enterprise.Enterprise" value=gov.gdgs.enterprise.Enterprise
key="1100" value=gov.gdgs.enterprise.Company

Why could not get the subclass's class?

Thanks a lot.


Top
 Profile  
 
 Post subject: Sorry, I made a mistake:should be table-per-class hierarchy
PostPosted: Wed Dec 24, 2003 10:15 pm 
Newbie

Joined: Wed Dec 24, 2003 9:17 pm
Posts: 6
Sorry.

_________________
Can fly means free.


Top
 Profile  
 
 Post subject: I got it.
PostPosted: Wed Dec 24, 2003 11:48 pm 
Newbie

Joined: Wed Dec 24, 2003 9:17 pm
Posts: 6
FT, the reason is in the DB, the discriminator column is char(6) with real data has only 4 chars!

After mofied <subclass name="Company" discriminator-value="1100" > to
<subclass name="Company" discriminator-value="1100 " >, it's OK.

_________________
Can fly means free.


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.