Hi Everyone,
I am loading Objects from one table that are coming from many subclasses. So hibernate has to instanciate the Objects as subclasses that are being mapped in a singleclasstable Mapping.
When loading hibernate always crashed in the error that you can see in the subject + de.datentraum.accounting.Account (Discriminator: AGRP )
So Hibernate is saying, that the object belonging to class discremenated with AGRP does not exist.
Whats the problem? When you look behind the discriminator you can see, that the brackets are not directly to the discriminator. There is a whitespace coming from the database, that should not be there. But when looking in persister, hibernate looks for "AGRP" and not "AGRP ". Nothing is found. So the class is not mapped by the persister.
The field I used was a textfield with size 5.
No i solved this problem with fixing the discriminator lenght. Another solution could be trimming the discriminator in the hibernatcode to avoid such problems. I have been searching quiet long.
Would there speak anything against trimming the discriminator in this method??
FROM CLASS Loader
Code:
/**
* Determine the concrete class of an instance in the <tt>ResultSet</tt>
*/
private String getInstanceClass(
final ResultSet rs,
final int i,
final Loadable persister,
final Serializable id,
final SessionImplementor session)
throws HibernateException, SQLException {
if ( persister.hasSubclasses() ) {
// Code to handle subclasses of topClass
Object discriminatorValue = persister.getDiscriminatorType().nullSafeGet(
rs,
getEntityAliases()[i].getSuffixedDiscriminatorAlias(),
session,
null
);
final String result = persister.getSubclassForDiscriminatorValue( discriminatorValue ); // TRIMMING HERE COULD HELP AVOID WHITESPACE PROBLEMS
if ( result == null ) {
//woops we got an instance of another class hierarchy branch
throw new WrongClassException(
"Discriminator: " + discriminatorValue,
id,
persister.getEntityName()
);
}
return result;
}
else {
return persister.getEntityName();
}
}
Hope i could help some people having the same problem by posting this.
Regards,
Alexander