[jboss-user] [EJB 3.0] - hibernate and inheritance

p.chevillon do-not-reply at jboss.com
Fri Nov 30 10:19:55 EST 2007


Hello,

I've a problem with requests on sublasses of a class tree (Entity beans). I got a org.hibernate.WrongClassException when trying to access data with a oneToMany relation.

My architecture is:

A <---- B <---- C


  | @Entity
  | @Table(name = "A")
  | @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  | @DiscriminatorColumn(name = "DTYPE", discriminatorType = DiscriminatorType.STRING)
  | @DiscriminatorValue("A_TYPE")
  | public class A implements java.io.Serializable {
  | 
  | 	private Long id;
  | ...
  | }
  | 
  | @Entity
  | @DiscriminatorValue("B_TYPE")
  | public class B extends A {
  | 	
  | 	// Associations
  | 	private Collection<Obj> objSet = new ArrayList<Obj>();
  | 
  |         @OneToMany(mappedBy = "A")
  | 	public Collection<Review> getObjSet() {
  | 		return objSet;
  | 	}
  | 
  | 	public void setObjSet(Collection<Obj> objSet) {
  | 		this.objSet = objSet;
  | 	}
  | }
  | 
  | @Entity
  | @DiscriminatorValue("C_TYPE")
  | public class C extends B {
  |        ...
  | }
  | 
  | 

And Obj is defined like:


  | @Entity
  | @Table(name = "OBJ")
  | public class Obj {
  |         private B value;
  | 
  |         @ManyToOne
  | 	@JoinColumn(name="A_ID")
  | 	public AppPOI getValue() {
  | 		return value;
  | 	}
  | 
  | 	public void setValue(B value) {
  | 		this.value = value;
  | 	}
  | 
  | }
  | 

When I create a new Obj and associate it to a B Entity it works. (correctly added to the DB, good ID pointing from OBJ to a "A like" entry)

Now when I try to access using this request:
SELECT obj FROM Obj obj	WHERE obj.value.id=44549450

It gives me that error message:

  | org.hibernate.WrongClassException: Object with id: 44549450 was not of the specified subclass: C (Discriminator: B_TYPE)
  | 

I'm using using jboss 4.0.5 with seam and hibernate updated to version 3.2.5ga

Thanks for your help, I couldn't find an answer to my problem with the search function of this forum, I've passed so many times reading it at this point...

Paulin



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4109352#4109352

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4109352



More information about the jboss-user mailing list