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: mapping a parameterized class
PostPosted: Tue Mar 09, 2010 10:02 am 
Newbie

Joined: Mon Aug 31, 2009 1:19 pm
Posts: 11
Hello, I have something like this:

Code:
public abstract class MyClass<E extends MyAbstractEntity> implements Serializable{
   
   private static final long serialVersionUID = 2832228828007049949L;
   
   private Long id;
   protected E myEntity;
   
         
   @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
   public Long getId() {
      return id;
   }
   @SuppressWarnings("unused")
   private void setId(Long id) {
      this.id = id;
   }
   
      
   @OneToOne(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
   public E getMyEntity() {
      return myEntity;
   }
   @SuppressWarnings("unused")
   private void setMyEntity(M myEntity) {
      this.myEntity = myEntity;
   }
}

public class MyEspecificClass extends MyClass<MyEspecificEntity>{

   private static final long serialVersionUID = 6451465817583035678L;

...Some specific methods...
   
}


the problem here is that when I persist a myEspecificClass object, Hibernate doesn't persist the myEspecificEntity with the correct class.

Could anyone help me?
Have anyone done something like that in the past?

Regards,
Chiara


Top
 Profile  
 
 Post subject: Re: mapping a parameterized class
PostPosted: Tue Mar 09, 2010 11:19 am 
Newbie

Joined: Mon Aug 31, 2009 1:19 pm
Posts: 11
I found the solution.

In every subclass I need to redefine the map anotation like this:
Code:
public abstract class MyClass<E extends MyAbstractEntity> implements Serializable{
   ...
   protected E myEntity;
  ...     
   abstract public E getMyEntity();
}

public class MyEspecificClass extends MyClass<MyEspecificEntity>{

   private static final long serialVersionUID = 6451465817583035678L;

   @OneToOne(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
   public MyEspecificEntity getMyEntity(){
       return myEntity;
   }
   
}


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.