2016-11-14 103 views
0

大家早上好! 我正嘗試使用Hibernate來閱讀使用Eclipse Java中的MSACCESS數據庫,但它給了我一個MappingException休眠無效配置映射

這裏是我的hibernateaccess.cfg.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-mapping SYSTEM 
    "classpath://org/hibernate/hibernate-mapping-3.0.dtd"> 
<hibernate-mapping> 
    <session-factory> 

     <property name='connection.driver_class'>net.ucanaccess.jdbc.UcanaccessDriver</property> 
     <property name='connection.username'></property> 
     <property name='connection.password'></property> 

     <!-- JDBC connection pool (use the built-in) --> 
     <property name='connection.pool_size'>1000</property> 

     <property name="hibernate.c3p0.min_size">2</property> 
     <property name="hibernate.c3p0.max_size">600000</property> 

     <!-- SQL dialect --> 
     <property name='dialect'>dialect.MSAccessDialect</property> 

     <!-- Echo all executed SQL to stdout --> 
     <property name='show_sql'>true</property> 

     <!-- Mapping files --> 

     <mapping class="TransporteAccess.hbm.xml" /> 
    </session-factory> 
</hibernate-mapping> 

和TransporteAccess.hbm.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-mapping SYSTEM 
    "classpath://org/hibernate/hibernate-mapping-3.0.dtd"> 
<hibernate-mapping> 
    <class name="model.Transporte" table="Transportes"> 
     <property name="transporte" column="TRANSPORTES" type="string"></property> 
    </class> 
</hibernate-mapping> 

我在做什麼錯? 非常感謝!

回答

1

這是強制性的在Hibernate的主鍵,refer 添加主鍵爲好,

<id name="id" type="int" column="id"> 
    <generator class="native"/> 
</id> 

除了這個hibernateaccess.xml包含了一些無關緊要的標籤

更新在hibernateaccess頂線。 XML與

<?xml version='1.0' encoding='utf-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC 
     "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
     "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
    <session-factory> 

&變化

<mapping class="TransporteAccess.hbm.xml" /> 

<mapping resource="TransporteAccess.hbm.xml" /> 
+0

但表hasn't主鍵(IIT是沒有信息學人的舊數據庫maden) – vLopez

+0

只需添加默認的主鍵的默認行爲,Hibernate不會不工作主鍵 –

+0

已添加並且無法正常工作,我認爲錯誤來自Hibernateaccess.cfg.xml,因爲如果我評論錯誤仍然存​​在 – vLopez