Oleg
Oleg

Reputation: 179

One-to-many : Join table not found error

I am trying to persist an object InstrumentDefinition that has a list of object InstrumentId.

I am using XML to do the mapping (not allowed to use annotations).

<entity name="InstrumentDefinition" class="model.InstrumentDefinition" access="FIELD">

  <table name="T_INSTRUMENT_DEFINITION"/>

  <attributes>

     <id name="symbol">
        <column name="SYMBOL" length="100" />
     </id>

     <basic name="product">
        <column name="PRODUCT" length="100"/>
     </basic>

     <basic name="securityExchange">
        <column name="SECURITY_EXCHANGE" length="100"/>
     </basic>

     <basic name="currency">
        <column name="CURRENCY" length="100"/>
     </basic>

     <basic name="product">
        <column name="PRODUCT" length="100"/>
     </basic>

     <one-to-many name="instrumentIdList" fetch="EAGER">
        <map-key name="value"/>
    </one-to-many>

  </attributes>
</entity>

.

<entity name="InstrumentId" class="org.fpml.v57.InstrumentId" access="FIELD">

  <table name="T_INSTRUMENT_ID"/>

  <attributes>

     <id name="instrumentIdScheme">
        <column name="INSTRUMENT_ID_SCHEME" length="100"/>
     </id>

     <id name="value">
        <column name="VALUE" length="100"/>
     </id>

  </attributes>

When starting my project, Hibernate complains it doesn't find the table T_INSTRUMENT_DEFINITION_T_INSTRUMENT_ID.

I assume something is missing in my configuration but have no idea what.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="UniverseManagerServicePersistenceUnit" transaction-type="JTA">
 <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
  <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=UniverseManagerServicePersistenceDataSource)</jta-data-source>
  <mapping-file>META-INF/mapping/org/fpml/v57/InstrumentId.xml</mapping-file>                  
  <mapping-file>META-INF/mapping/model/InstrumentDefinition.xml</mapping-file>    
  <exclude-unlisted-classes>true</exclude-unlisted-classes>
  <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
  <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>

Also, I didn't find any extensive documentation on XML mapping for hibernate. The only doc I found is very short on it (https://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/xml-overriding.html)

Upvotes: 0

Views: 752

Answers (1)

Neil Stockton
Neil Stockton

Reputation: 11531

Perhaps putting <join-column> within the <one-to-many> will make Hibernate think it has a FK rather than join table

Upvotes: 2

Related Questions