开发者

Hibernate unidirectional one-to-many.i'm a bit confused

Hello guys sorry if the question looks stupid to you. i have 3 tables currency (id | name) language (id| name | description) transaction (id|amount|languageId | currencyid)

so i want to insert into the transaction but making sure that it doesn't insert unknown language or currency (meaning it shouldn't insert to messagetemplate if there is no existing parent language and currency)

here are my mapping files

<?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 package="com.myproject.model">
 <class name="Transaction" table="transaction">
  <id name="id">
    <generator class="native"/>
  </id>
  <property column="amount" name="amount" type="String"/>
  <many-to-one class="CurrencyImpl" column="currency" name="currency"/>
  <many-to-one class="LanguageImpl" column="language" name="language"/>
 </class>
</hibernate-mapping>

<?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 package="com.myproject.model">开发者_StackOverflow社区
  <class name="Currency" table="currency">
   <id name="id">
    <generator class="native"/>
   </id>
   <property column="currency_name" name="name" type="String"/>
  </class>
</hibernate-mapping>


<?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 package="com.myproject.model">
 <class name="Language" table="language">
  <id name="id">
    <generator class="native"/>
  </id>
  <property column="language_name" name="name" type="String"/>
  <property column="language_description" name="description" type="String"/>
 </class>
</hibernate-mapping>

with this current mapping it's seems not to be the case.how to achieve that? thanks a lot for reading


You're many to one references CurrencyImpl and LanguageImpl, but those classes are not mapped, only the (presumably corresponding) interfaces. I suggest you begin by creating and mapping only concrete classes and get that working before trying to mess about with mapping interfaces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜