-->
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: org.hibernate.WrongClassException
PostPosted: Thu Aug 02, 2007 4:54 am 
Newbie

Joined: Thu Aug 02, 2007 3:42 am
Posts: 1
Need help with Hibernate?

Code:
@Table(name="PERMISSION")
@DiscriminatorColumn(name="TYPE",...)
public abstract class Permission {..}

@DiscriminatorValue("SERVERSIDE")
class ServerSidePermission extends Permission {...}

@DiscriminatorValue("CLIENTSIDE")
class ClientSidePermission extends Permission {...}


<< class Role >> has these mapping definitions:
Code:
   @ManyToMany(targetEntity = ServerSidePermission.class, fetch = FetchType.EAGER)
   @JoinTable(name = "ROLE_PERMISSION", joinColumns = {
         @JoinColumn(name="ROLE_ID")
   }, inverseJoinColumns = {
         @JoinColumn(name="PERMISSION_ID")
   })
   private Set<ServerSidePermission> serverSidePermissions;
   
   @ManyToMany(targetEntity = ClientSidePermission.class, fetch = FetchType.EAGER)
   @JoinTable(name = "ROLE_PERMISSION", joinColumns = {
         @JoinColumn(name="ROLE_ID")
   }, inverseJoinColumns = {
         @JoinColumn(name="PERMISSION_ID")
   })
   private Set<ClientSidePermission> clientSidePermissions;


When I try to load Role bean, this exception is thrown:

Code:
org.hibernate.WrongClassException: Object with id: 3 was not of the specified subclass: ServerSidePermission (loaded object was of wrong class)
   at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:1235)
   at org.hibernate.loader.Loader.getRow(Loader.java:1186)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:569)
   at org.hibernate.loader.Loader.doQuery(Loader.java:689)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
   at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)


The generated SQLs are

select serverside0_.ROLE_ID as ROLE1_1_, serverside0_.PERMISSION_ID as PERMISSION2_1_, serverside1_.ID as ID58_0_, serverside1_.NAME as NAME58_0_, serverside1_.DESCRIPTION as DESCRIPT4_58_0_ from CORPORATE.U_ROLE_PERMISSION serverside0_ left outer join CORPORATE.U_PERMISSION serverside1_ on serverside0_.PERMISSION_ID=serverside1_.ID where serverside0_.ROLE_ID=?

select clientside0_.ROLE_ID as ROLE1_1_, clientside0_.PERMISSION_ID as PERMISSION2_1_, clientside1_.ID as ID58_0_, clientside1_.NAME as NAME58_0_, clientside1_.DESCRIPTION as DESCRIPT4_58_0_ from CORPORATE.U_ROLE_PERMISSION clientside0_ left outer join CORPORATE.U_PERMISSION clientside1_ on clientside0_.PERMISSION_ID=clientside1_.ID where clientside0_.ROLE_ID=?


But there is no condition like clientside1_.TYPE='SERVERSIDE' in where clause. I think It should be cause of the discriminator definitions in subclasses.


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.