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?
You will have to make sure that you have testdb database available in your MySQL database and you have a user test available to access the database. The XML configuration file must conform to the Hibernate 3 Configuration DTD, which is available at http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd.
To connect Java with MS Access, you need a JDBC driver. Although Microsoft do not produce a JDBC driver for MS Access, Easysoft provide two Microsoft Access JDBC drivers. Use these JDBC drivers to provide the connectivity layer between your Java code and MS Access database.
Microsoft doesn't have any plans to replace Microsoft Access while also planning to remove the application from Office 365. Therefore, Access users will need to look at alternative systems to run their desktop databases, such as LibreOffice Base, Zoho Creator, or Bubble.
Is Microsoft Access dead? No, Microsoft have no plans to end Microsoft Access. They are committed to its development. See this video from Access Program Manager Ebo Quansah where he confirms that Microsoft will continue to develop Access and included it in future releases of Office.
Actual solution here!
After spending 1 day trying out different solutions ODBC, HXTT, etc. I found this beauty :) 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
<?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:
<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. ;)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With