-->
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.  [ 1 post ] 
Author Message
 Post subject: Object with id: 76 was not of the specified subclass SOLVED!
PostPosted: Fri Sep 07, 2007 12:44 pm 
Beginner
Beginner

Joined: Tue Mar 15, 2005 5:04 am
Posts: 26
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.