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.
|