java - Spring Hibernate inheritance wrong class instanciate -


i'm using spring 4 , hibernate have inheritance structure in hibernate , spring: generic class 'resourcestate' , subclass 'videostate' , 'audiostate'

my problem hibernate generate instance of 'resourcestate' instead 'videostate' or 'audiostate' instance...

sql code:

create table `resource_state` (   `id` bigint(20) unsigned not null auto_increment,   primary key (`id`) ) engine=innodb auto_increment=6 default charset=utf8;  create table `video_state` (   `resource_state_id` bigint(20) unsigned not null,   `reproduction_point` int(10) unsigned not null default '0',   `volume` decimal(10,5) unsigned not null default '100.00000',   `state` int(2) not null default '-1',   primary key (`resource_state_id`) ) engine=innodb default charset=utf8;  create table `audio_state` (   `resource_state_id` bigint(20) unsigned not null,   `reproduction_point` int(10) unsigned not null default '0',   `volume` decimal(10,5) unsigned not null default '100.00000',   `state` int(2) not null default '-1',   primary key (`resource_state_id`) ) engine=innodb default charset=utf8; 

java code:

@entity @table(name = "resource_state") @inheritance(strategy=inheritancetype.joined) public class resourcestate {      @id     @generatedvalue     @column(name = "id")     private long id;      public long getid() {         return id;     }      public void setid(long id) {         this.id = id;     }  @entity @table(name="audio_state") @primarykeyjoincolumn(name="resource_state_id") public class audiostate extends resourcestate{      @column(name="reproduction_point")     private integer reproductionpoint;     @column(name="volume")     private double volume;     @column(name="state")     private integer state;      public integer getreproductionpoint() {         return reproductionpoint;     }     public void setreproductionpoint(integer reproductionpoint) {         this.reproductionpoint = reproductionpoint;     }     public double getvolume() {         return volume;     }     public void setvolume(double volume) {         this.volume = volume;     }     public integer getstate() {         return state;     }     public void setstate(integer state) {         this.state = state;     }  @entity @table(name="video_state") @primarykeyjoincolumn(name="resource_state_id") public class videostate extends resourcestate{      @column(name="reproduction_point")     private integer reproductionpoint;     @column(name="volume")     private double volume;     @column(name="state")     private integer state;      public integer getreproductionpoint() {         return reproductionpoint;     }     public void setreproductionpoint(integer reproductionpoint) {         this.reproductionpoint = reproductionpoint;     }     public double getvolume() {         return volume;     }     public void setvolume(double volume) {         this.volume = volume;     }     public integer getstate() {         return state;     }     public void setstate(integer state) {         this.state = state;     }  @entity @table(name="user_has_resource") public class userhasresource {      @id     @generatedvalue     @column(name="id")     private long id;      @manytoone(fetch = fetchtype.eager)     @joincolumn(name = "user_id")     private user user;      @manytoone(fetch=fetchtype.eager)     @joincolumn(name="resource_id")     private resource resource;      @onetoone(fetch = fetchtype.eager)     @joincolumn(name="resource_state_id")     private resourcestate resourcestate;      public userhasresource() {}      public long getid() {         return id;     }      public void setid(long id) {         this.id = id;     }      public user getuser() {         return user;     }      public void setuser(user user) {         this.user = user;     }      public resource getresource() {         return resource;     }      public void setresource(resource resource) {         this.resource = resource;     }      public resourcestate getresourcestate() {         return resourcestate;     }      public void setresourcestate(resourcestate resourcestate) {         this.resourcestate = resourcestate;     }    } 

and hibernate config:

<?xml version='1.0' encoding='utf-8'?> <!doctype hibernate-configuration public         "-//hibernate/hibernate configuration dtd 3.0//en"         "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration>           <session-factory>     <property name="hibernate.dialect"> org.hibernate.dialect.hsqldialect</property>     <property name="show_sql">true</property>     <property name="hbm2ddl.auto">create</property>       <mapping class="it.unica.model.user" />     <mapping class="it.unica.model.video"/>     <mapping class="it.unica.model.audio"/>     <mapping class="it.unica.model.resource"/>     <mapping class="it.unica.model.resourcestate"/>     <mapping class="it.unica.model.videostate"/>     <mapping class="it.unica.model.audiostate"/>     <mapping class="it.unica.model.device"/>     <mapping class="it.unica.model.userindevice"/>     <mapping class="it.unica.model.userhasresource"/>   </session-factory> </hibernate-configuration> 

i don't understand why hibernate don't make correct class instance.

thanks helping.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -