一对多:连接表未找到错误

时间:2015-05-18 15:33:10

标签: java xml hibernate jpa

我正在尝试保留一个对象 InstrumentDefinition ,该对象具有一个对象列表 InstrumentId

我使用XML进行映射(不允许使用注释)。

<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>

启动项目时,Hibernate抱怨它找不到表T_INSTRUMENT_DEFINITION_T_INSTRUMENT_ID。

我假设我的配置中缺少某些东西,但不知道是什么。

<?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>

另外,我没有找到关于hibernate的XML映射的任何大量文档。我发现的唯一文档很短(https://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/xml-overriding.html

1 个答案:

答案 0 :(得分:2)

或许将<join-column>放在<one-to-many>中会使Hibernate认为它有FK而不是连接表