Oops! Hibernate + Access Quick Start

Oops! Hibernate + Access Quick Start
Oops! Hibernate + Access Quick Start

Purpose:

为了用hibernate链接access,花了我一个下午。他nnd,网上一群混蛋,没有一篇能够说明为什么的。


Reference:

Eclipse + Access
http://www.blogjava.net/pixysoft/archive/2007/08/30/141392.html

Eclipse + Hibernate
http://www.blogjava.net/pixysoft/archive/2007/09/01/141932.html

Quick Start:

所有的步骤参考上面的文章,几乎没有变,下面2个文件修改就行了。

假设我的access数据库保存在c:\demo.mdb,数据格式:

表名:CUSTOMER
字段:
id 自增,主键
username: 文本
password: 文本

则:
Customer.hbm.xml
<? xml version="1.0" ?>
<! DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"
>

< hibernate-mapping >
    
< class  name ="Customer"  table ="CUSTOMER" >
        
< id  name ="id"  column ="id" >
            
< generator  class ="increment"   />
        
</ id >
        
< property  name ="username"  column ="USERNAME"   />
        
< property  name ="password"  column ="PASSWORD"   />
    
</ class >
</ hibernate-mapping >


hibernate.cfg.xml

<? xml version="1.0" encoding="utf-8"  ?>
<! DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"
>

< hibernate-configuration >
    
    
< session-factory  name ="java:/hibernate/HibernateFactory" >
        
        
< property  name ="show_sql" > true </ property >
        
< property  name ="connection.driver_class" >
            sun.jdbc.odbc.JdbcOdbcDriver
<!--  这里是Access的JDBCdriverclass名  -->
        
</ property >
        
< property  name ="connection.url" >
            jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:/demo.mdb
        
</ property >
        
< property  name ="connection.username" >
            sa
        
</ property >
        
< property  name ="connection.password" >          
        
</ property >
        
< property  name ="dialect" >
            org.hibernate.dialect.MySQLDialect
        
</ property >
        
        
< mapping  resource ="Customer.hbm.xml"   />         
    
</ session-factory >
    
</ hibernate-configuration >

你可能感兴趣的:(Oops! Hibernate + Access Quick Start)