-->
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.  [ 2 posts ] 
Author Message
 Post subject: collection of base class throws WrongClassException
PostPosted: Sun Mar 21, 2010 1:57 pm 
Newbie

Joined: Sun Mar 21, 2010 12:24 am
Posts: 2
Hi,
I have annotated a class PackageProfile which contains a set of AbstractPackages, when I tried to load the class, I got
the WrongClassException.
Here is the class hierachy.
PackageProfile extends AbstractProfile,
Package extends AbstractPackage.
There is ManyToMany relationship between PackageProfile and AbstractPackage.
Here is my annotated code:
Code:
@Entity
@Table(name="PF_PROFILES")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "objecttype")
public class AbstractProfile extends BasicModel implements Serializable {
   @Id
   @GenericGenerator(name="generator", strategy = "increment")
   @Column(name="id")
   @GeneratedValue(generator = "generator")
   long id;

   @Column(name="profileType")
   String profileType;
   ...
}
@Entity
@DiscriminatorValue("PackageProfile")
public class PackageProfile extends AbstractProfile {
   @ManyToMany(
         cascade = {CascadeType.PERSIST, CascadeType.MERGE},
         fetch = FetchType.EAGER
   )
   @JoinTable(
         name="PF_PROFILES_PACKAGES",
         joinColumns= {@JoinColumn(name="PROFILE_ID")},
         inverseJoinColumns= {@JoinColumn(name="PACKAGE_ID")}
   )
   @Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
   Set<AbstractPackage> packages = new HashSet();
...
}

@Entity
@Table(name="PF_PACKAGES")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
      name="objecttype",
      discriminatorType=DiscriminatorType.STRING
)
public class AbstractPackage extends BasicModel implements Serializable {
   @Id
   @GenericGenerator(name="generator", strategy = "increment")
   @GeneratedValue(generator = "generator")
   long id;
...
}


@Entity
@DiscriminatorValue("Package")
public class Package extends AbstractPackage {

   @Type(type = "text")
   String content;
}



When my test code does session.load(PackageProfile.class, new Integer(id)),
I got the following hibernate exception:
testPackageProfile(com.vmware.vum.pf.impl.base.persistence.ProfileTest) Time elapsed: 0.078 sec <<< ERROR!
org.hibernate.WrongClassException: Object with id: 1 was not of the specified subclass: com.vmware.vum.pf.model.Abstract
Package (Discriminator: Package )
at org.hibernate.loader.Loader.getInstanceClass(Loader.java:1477)
...

We just started to use hibernate. Is there something wrong with my annotations or Is this a bug?
Any help is greatly appreciated!
thanks.


Top
 Profile  
 
 Post subject: Re: collection of base class throws WrongClassException
PostPosted: Sun Mar 21, 2010 2:06 pm 
Newbie

Joined: Sun Mar 21, 2010 12:24 am
Posts: 2
I found the cause of WrongClassException, I have to define my discriminator column width to be the exact length
of the discriminator value. Otherwise, hibernate fills the rest of the string with blank spaces and hence the complaint. I am using derby embedded db, is this a bug in hibernate?


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