如何在MS Access中使用hibernate?

时间:2021-11-09 11:49:47

I want to use hibernate with MS Access. Which dialect should I use and can you give me a sample hibernate configuration file with MS Access?

我想在MS Access中使用hibernate。我应该使用哪种方言,你能给我一个带MS Access的示例hibernate配置文件吗?

5 个解决方案

#1


12  

For MS Access, you'll need the dialect from HXTT. You'll need to use the hibernate support package provided by HXTT. There is also a sample project that you can check for a fully working example.

对于MS Access,您需要HXTT的方言。您需要使用HXTT提供的hibernate支持包。还有一个示例项目,您可以检查完整的工作示例。

Below, a sample minimal configuration:

下面是一个最小配置示例:

# Hxtt Access dialect sample
hibernate.dialect=com.hxtt.support.hibernate.HxttAccessDialect
hibernate.connection.driver_class=com.hxtt.sql.access.AccessDriver
hibernate.connection.url=jdbc:access:///c:/yourAccessDirectory

PS: If MS Access is not a written in stone requirement, maybe you should consider using something else like... well, anything.

PS:如果MS Access不是书面要求,也许你应该考虑使用其他东西,比如......好吧,什么。

#2


10  

Actual solution here!

实际的解决方案!

After spending 1 day trying out different solutions ODBC, HXTT, etc. I found this beauty :) http://ucanaccess.sourceforge.net/site.html.

花了一天时间尝试不同的解决方案ODBC,HXTT等我找到了这个美女:) http://ucanaccess.sourceforge.net/site.html。

It couldn't be any simpler: just add the jars from the site to your project libs and.

它可能不是更简单:只需将网站中的罐子添加到项目库中即可。

META-INF/persistence.xml

META-INF / persistence.xml中

<?xml version="1.0" encoding="utf-8"?>
<persistence>
    <persistence-unit name="traderMandate">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
            <property name="hibernate.connection.url" value="jdbc:ucanaccess://C:/MY.accdb;" />
            <property name="hibernate.connection.driver_class" value="net.ucanaccess.jdbc.UcanaccessDriver"/>
            <property name="hibernate.archive.autodetection" value="class" />
        </properties>
    </persistence-unit>
</persistence>          

Spring config:

Spring配置:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="traderMandate"/>
</bean>

<tx:annotation-driven/>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

And you're good to go. ;)

你很高兴去。 ;)

#3


1  

@Firstthumb. Sorry, this is not really an answer but just expressing a comment. I was in the same boat - considering using MS Access to develop a local tipping competition for the Football World Cup 2010. I could access MS Access directly using the Oledb but as a training exercise to reskill a bunch of Java developers moving to .NET, I wanted to show the usage of nHibernate as the DAO layer.

@Firstthumb。对不起,这不是一个真正的答案,只是表达评论。我在同一条船上 - 考虑使用MS Access为2010年足球世界杯开发本地小费比赛。我可以使用Oledb直接访问MS Access,但作为一项训练练习,重新开始转移到.NET的Java开发人员,我想展示nHibernate作为DAO层的用法。

After investigating the non-availability of a robust and supported dialect from JBoss/Hibernate team and other considerations, I decided to forego the exercise on using MSAccess. I downloaded the free SQL Express 2008 instead.

在调查了来自JBoss / Hibernate团队的强大且支持的方言的不可用性以及其他考虑因素之后,我决定放弃使用MSAccess的练习。我下载了免费的SQL Express 2008。

For those who still want to use MSAccess in .NET, please see this link)

对于那些仍想在.NET中使用MSAccess的人,请看这个链接)

#4


1  

You can use an other strategy and a free strategy to resolve this problem (HXTT is not free) :

您可以使用其他策略和免费策略来解决此问题(HXTT不是免费的):

http://www.programmingforfuture.com/2011/06/how-to-use-ms-access-with-hibernate.html

http://www.programmingforfuture.com/2011/06/how-to-use-ms-access-with-hibernate.html

Personaly I got an exception when I try to reverse engineering the ms database (org.hibernate.exception.GenericJDBCException: Error while reading primary key meta data), yet it works for many people.

Personaly我尝试逆向工程ms数据库时遇到异常(org.hibernate.exception.GenericJDBCException:读取主键元数据时出错),但它适用于很多人。

#5


1  

As a late note (commenting is not available for me): UCanAccess surely works, although I don't (yet) have experience with writing data. Anyways, regarding the dialect to use, I run with

作为一个迟到的注释(评论不适合我):UCanAccess肯定有效,虽然我(还)没有编写数据的经验。无论如何,关于使用的方言,我跑

            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>

because UCanAccess use HSQLDB, and I suppose that dialect is the best match. There isn't any sql actually hitting ms-access in the picture here, jackcess reads and writes directly to the access mdb-file, there is no microsoft code interpreting any sql anywhere, as far as I can understand, and therefore using SQLServerDialect will only confuse HSQLDB code trying to understand it.

因为UCanAccess使用HSQLDB,我认为方言是最佳匹配。这里没有任何sql实际点击ms-access,jackcess直接读取和写入访问mdb文件,根据我的理解,没有微软代码在任何地方解释任何sql,因此使用SQLServerDialect将只是混淆尝试理解它的HSQLDB代码。

#1


12  

For MS Access, you'll need the dialect from HXTT. You'll need to use the hibernate support package provided by HXTT. There is also a sample project that you can check for a fully working example.

对于MS Access,您需要HXTT的方言。您需要使用HXTT提供的hibernate支持包。还有一个示例项目,您可以检查完整的工作示例。

Below, a sample minimal configuration:

下面是一个最小配置示例:

# Hxtt Access dialect sample
hibernate.dialect=com.hxtt.support.hibernate.HxttAccessDialect
hibernate.connection.driver_class=com.hxtt.sql.access.AccessDriver
hibernate.connection.url=jdbc:access:///c:/yourAccessDirectory

PS: If MS Access is not a written in stone requirement, maybe you should consider using something else like... well, anything.

PS:如果MS Access不是书面要求,也许你应该考虑使用其他东西,比如......好吧,什么。

#2


10  

Actual solution here!

实际的解决方案!

After spending 1 day trying out different solutions ODBC, HXTT, etc. I found this beauty :) http://ucanaccess.sourceforge.net/site.html.

花了一天时间尝试不同的解决方案ODBC,HXTT等我找到了这个美女:) http://ucanaccess.sourceforge.net/site.html。

It couldn't be any simpler: just add the jars from the site to your project libs and.

它可能不是更简单:只需将网站中的罐子添加到项目库中即可。

META-INF/persistence.xml

META-INF / persistence.xml中

<?xml version="1.0" encoding="utf-8"?>
<persistence>
    <persistence-unit name="traderMandate">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
            <property name="hibernate.connection.url" value="jdbc:ucanaccess://C:/MY.accdb;" />
            <property name="hibernate.connection.driver_class" value="net.ucanaccess.jdbc.UcanaccessDriver"/>
            <property name="hibernate.archive.autodetection" value="class" />
        </properties>
    </persistence-unit>
</persistence>          

Spring config:

Spring配置:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="traderMandate"/>
</bean>

<tx:annotation-driven/>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

And you're good to go. ;)

你很高兴去。 ;)

#3


1  

@Firstthumb. Sorry, this is not really an answer but just expressing a comment. I was in the same boat - considering using MS Access to develop a local tipping competition for the Football World Cup 2010. I could access MS Access directly using the Oledb but as a training exercise to reskill a bunch of Java developers moving to .NET, I wanted to show the usage of nHibernate as the DAO layer.

@Firstthumb。对不起,这不是一个真正的答案,只是表达评论。我在同一条船上 - 考虑使用MS Access为2010年足球世界杯开发本地小费比赛。我可以使用Oledb直接访问MS Access,但作为一项训练练习,重新开始转移到.NET的Java开发人员,我想展示nHibernate作为DAO层的用法。

After investigating the non-availability of a robust and supported dialect from JBoss/Hibernate team and other considerations, I decided to forego the exercise on using MSAccess. I downloaded the free SQL Express 2008 instead.

在调查了来自JBoss / Hibernate团队的强大且支持的方言的不可用性以及其他考虑因素之后,我决定放弃使用MSAccess的练习。我下载了免费的SQL Express 2008。

For those who still want to use MSAccess in .NET, please see this link)

对于那些仍想在.NET中使用MSAccess的人,请看这个链接)

#4


1  

You can use an other strategy and a free strategy to resolve this problem (HXTT is not free) :

您可以使用其他策略和免费策略来解决此问题(HXTT不是免费的):

http://www.programmingforfuture.com/2011/06/how-to-use-ms-access-with-hibernate.html

http://www.programmingforfuture.com/2011/06/how-to-use-ms-access-with-hibernate.html

Personaly I got an exception when I try to reverse engineering the ms database (org.hibernate.exception.GenericJDBCException: Error while reading primary key meta data), yet it works for many people.

Personaly我尝试逆向工程ms数据库时遇到异常(org.hibernate.exception.GenericJDBCException:读取主键元数据时出错),但它适用于很多人。

#5


1  

As a late note (commenting is not available for me): UCanAccess surely works, although I don't (yet) have experience with writing data. Anyways, regarding the dialect to use, I run with

作为一个迟到的注释(评论不适合我):UCanAccess肯定有效,虽然我(还)没有编写数据的经验。无论如何,关于使用的方言,我跑

            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>

because UCanAccess use HSQLDB, and I suppose that dialect is the best match. There isn't any sql actually hitting ms-access in the picture here, jackcess reads and writes directly to the access mdb-file, there is no microsoft code interpreting any sql anywhere, as far as I can understand, and therefore using SQLServerDialect will only confuse HSQLDB code trying to understand it.

因为UCanAccess使用HSQLDB,我认为方言是最佳匹配。这里没有任何sql实际点击ms-access,jackcess直接读取和写入访问mdb文件,根据我的理解,没有微软代码在任何地方解释任何sql,因此使用SQLServerDialect将只是混淆尝试理解它的HSQLDB代码。