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.