This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't able to insert row in table per concrete class strategy .

 
Ganesh Choudhary
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 4 classes : Reservation, Disc (abstract class), AudioDisc, VideoDisc(both extending Disc Class).









Reservation.hbm.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="tableperconcretesubclass.Reservation" table="DB2ADMIN.RES_Test">
<id name="id" type="integer" column="ID" >
<generator class ="assigned"/>
</id>
<!-- <many-to-one name="disc" class="tableperconcretesubclass.Disc" column="DISC_ID" /> -->
<!-- <one-to-one name="disc" class="tableperconcretesubclass.Disc" /> -->

<property name="description" type="string" column="DESCRIPTION"></property>

<set name="discs" lazy="true" cascade="all" >
<key column="DISC_ID" />
<one-to-many class="tableperconcretesubclass.Disc"/>
</set>
</class>
</hibernate-mapping>


Disc.hbm.xml :


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="tableperconcretesubclass.Disc" abstract="true">
<id name="id" type="integer" column="ID" unsaved-value="0">
<generator class ="sequence"/>
</id>

<union-subclass name="tableperconcretesubclass.AudioDisc" extends="tableperconcretesubclass.Disc" lazy="false" table="DB2ADMIN.AUDIODISC_Test">

<property name="singer" type="string" column="SINGER" />
<property name="numOfSongs" type="int" column="NUM_OF_SONGS"/>
<set name="songs" lazy="true" cascade="all" >
<key column="AUDIODISC_ID" />
<one-to-many class="tableperconcretesubclass.Song"/>
</set>
</union-subclass>
<union-subclass name="tableperconcretesubclass.VideoDisc" extends="tableperconcretesubclass.Disc" lazy="true" table="DB2ADMIN.VIDEODISC_Test">
<property name="director" type="string" column="DIRECTOR" />
<property name="language" type="string" column="LANG"/>
</union-subclass>
</class>
</hibernate-mapping>


Song.hbm.xml :


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="tableperconcretesubclass.Song" table="DB2ADMIN.SONG_Test">
<id name="id" type="integer" column="ID" >
<generator class ="assigned"/>
</id>
<property name="title">
<column name="TITLE" />
</property>

<property name="movie">
<column name="MOVIE" />
</property>

</class>
</hibernate-mapping>




when i am running createEntity() method with property

<property name="hibernate.hbm2ddl.auto">create</property>


i am getting following exception :



I am not getting why it is trying to create DISC table when Disc class is abstract ? am i doing anything wrong ? Can anybody please help me ?

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic