views:

125

answers:

1

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"&gt;
<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"&gt;
<hibernate-mapping package="com.myproject.model">
  <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"&gt;
<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

+1  A: 

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.

Jherico
Interfaces can not be mapped in Hibernate (mapped-superclass notwithstanding); I'm guessing OP mangled the code before posting.
ChssPly76
I believe you can map interfaces if you're working with dynamic proxies, but working with interfaces at all in hibernate is automatically an edge case, hence my advice that he limit himself to concrete classes.
Jherico