-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: MS Access Dialect - supporting Identity column issue
PostPosted: Wed Nov 12, 2003 11:40 am 
Newbie

Joined: Wed Nov 12, 2003 11:07 am
Posts: 15
Location: Canada
Hi,

I am trying to use Hibernate with ms access. I extended Dialect calss as below:

public class MSAccessDialect extends Dialect {

.....
public String getIdentityColumnString() {
return "AutoIncrement NOT NULL";
}
.....
}


DDL statement I get buy runing SchemaExport looks like this:

create table Books (ID INTEGER AutoIncrement NOT NULL, Name VARCHAR(255) null, primary key (ID))

How can I remove INTEGER keyword for Identity column. Otherwise I will get a syntax error in Access.

Thanks,
-Kourosh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 2:24 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 10:01 am
Posts: 34
Location: florence, italy
You should create your own dialect for access. I tried it quite a while ago, but I kept having problems due to the limitations of the jdbc drivers for access. I since used sql server, mysql, postgres, informix with no comparable problems.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 2:35 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 10:01 am
Posts: 34
Location: florence, italy
actually this was my dialect:

public class MSAccessDialect extends Dialect {
public MSAccessDialect() {
super();
register( Types.BIT, "BIT" );
register( Types.BIGINT, "INTEGER" );
register( Types.SMALLINT, "SMALLINT" );
register( Types.TINYINT, "BYTE" );
register( Types.INTEGER, "INTEGER" );
register( Types.CHAR, "VARCHAR(1)" );
register( Types.VARCHAR, "VARCHAR($l)" );
register( Types.FLOAT, "DOUBLE" );
register( Types.DOUBLE, "DOUBLE" );
register( Types.DATE, "DATETIME" );
register( Types.TIME, "DATETIME" );
register( Types.TIMESTAMP, "DATETIME" );
register( Types.VARBINARY, "VARBINARY($l)" );
register( Types.NUMERIC, "NUMERIC" );

getDefaultProperties().setProperty(Environment.OUTER_JOIN,
"false");
getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE,
NO_BATCH);
}

public String getIdentityColumnString() {
return " counter ";
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 7:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
How about posting this to the Wiki. But please do put in a section that the JDBC-ODBC bridge is far from great (and should never be used in production).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 4:34 am 
Beginner
Beginner

Joined: Fri Aug 29, 2003 10:01 am
Posts: 34
Location: florence, italy
kadybeik : what jdbc driver are you using currently ? I would like to do some test with access with the current version. thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 10:41 am 
Newbie

Joined: Wed Nov 12, 2003 11:07 am
Posts: 15
Location: Canada
peterpumpkin wrote:
kadybeik : what jdbc driver are you using currently ? I would like to do some test with access with the current version. thanks


Hi there,

I am using standard sun's jdbc. Here is what I put in my access dialect:

<!-- MS ACCESS -->
<property name="hibernate.dialect" value="net.sf.hibernate.dialect.MSAccessDialect"/>
<property name="hibernate.conn.driver_class" value="sun.jdbc.odbc.JdbcOdbcDriver"/>
<property name="hibernate.conn.url" value="jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\hibernate_intro\accessdb.mdb"/>

I can connect to my access database and was able to create tables. Problem is with Identity column. Doesn't matter what we use Autoincrement or Counter, the SchemaExport generates DDL with INTEGER based on type of identity column before Autoincrement. I guess we should find a way to not to put column type if it is an Identity.

Thanks,
-Kourosh


Top
 Profile  
 
 Post subject: Hibernate 3 with Microsoft ms access 2000 odbc
PostPosted: Thu May 05, 2005 10:10 am 
Beginner
Beginner

Joined: Wed Sep 24, 2003 8:27 am
Posts: 36
Team.

Thanks for the posts above.

I have got it working with Hibernate with Microsoft ms access odbc, including inserts and reads with identity.

I am using hibernate 3.0 , JDK 1.4 and Microsoft ms access 200.

Here is the dialect class:-

Code:

package org.hibernate.dialect;

import java.sql.Types;

import org.hibernate.cfg.Environment;

/**
* @author Suchak.Jani
*/
public class MSAccessDialect extends Dialect {
   public MSAccessDialect() {
      super();
      registerColumnType( Types.BIT, "BIT" );
      registerColumnType( Types.BIGINT, "INTEGER" );
      registerColumnType( Types.SMALLINT, "SMALLINT" );
      registerColumnType( Types.TINYINT, "BYTE" );
      registerColumnType( Types.INTEGER, "INTEGER" );
      registerColumnType( Types.CHAR, "VARCHAR(1)" );
      registerColumnType( Types.VARCHAR, "VARCHAR($l)" );
      registerColumnType( Types.FLOAT, "DOUBLE" );
      registerColumnType( Types.DOUBLE, "DOUBLE" );
      registerColumnType( Types.DATE, "DATETIME" );
      registerColumnType( Types.TIME, "DATETIME" );
      registerColumnType( Types.TIMESTAMP, "DATETIME" );
      registerColumnType( Types.VARBINARY, "VARBINARY($l)" );
      registerColumnType( Types.NUMERIC, "NUMERIC" );

      getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE,NO_BATCH);
      }

      public String getIdentityColumnString() {
         //return " counter ";
         return "not null auto_number";
      }
      
      public String getIdentitySelectString() {
         return "select @@IDENTITY";
      }
}



Here is a test xml file which works :-

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

<hibernate-mapping>

   <class name="com.suchak.hibernatetest.domainobjects.Person" table="Person">
      <id
         name="ID"
         column="ID"
      >
<!-- The above ID is an Interger in java and Autonumber in Microsoft ms access -->
         <generator class="identity"/>
      </id>      
      <property name="firstName">
         <column name="FirstName"/>
      </property>
      <property name="lastName">
         <column name="LastName"/>
      </property>
   </class>

</hibernate-mapping>


Note:- Just to restate, the problems of still not being able to use Long still exist due to issues of the odbc driver. It has nothing to do with Hibernate.

Regards
Suchak Jani


Top
 Profile  
 
 Post subject: A few additional modifications...
PostPosted: Wed Oct 12, 2005 5:15 pm 
Newbie

Joined: Wed Jul 20, 2005 5:41 pm
Posts: 2
So I added some additional changes to suchakjani's code above. Basically the changes I made were to:

  • move dialect under an unsupported package. Just didn't feel right to me having it under org.hibernate.dialect since it isn't really being supported by the hibernate team (this is more to not confuse the "customer" I'm delivering this to)
  • Dialect.NO_BATCH apparently isn't defined in the newer versions of hibernate (can't remember which). I'm using 3.0.5, so I modified the code to address that effectively, *I think* with the line:
    Code:
    getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, "0");
  • I was also getting a problem with "select for update" type errors with the ODBC-JDBC driver so I added some code to work around that. This also might have been added so I could use a "native" id generator (which translates to the hilo generator). (I know this is all kinda vague, but I modified the dialect weeks ago and have been testing it/working through porting issues with my application so I've kinda forgot what I did exactly between then and now... sorry)


Anyway, I this seems to work for a relatively complex application that I wrote. As suchakjani says, Long's aren't supported due to limitation in the ODBC-JDBC bridge. Also, I couldn't get CLOB's working, which doesn't surprise me. The platform my app is currently running on is JDK 1.4, hibernate 3.0.5, access 2000.

Below is the code I'm using for a dialect for Access:

Code:
/*
* Created on Sep 23, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.hibernate.unsupported.dialect;

import java.sql.Types;

import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;

/**
* @author Suchak.Jani  w/ modifications by Eric Klimas
* This code is blatently ripped off from the Hibernate forums discussion
* on MS Access and Hibernate found here:
* <a href="http://forums.hibernate.org/viewtopic.php?p=2178009&sid=876222db25ab13214a3729dbe1e494b6">
* http://forums.hibernate.org/viewtopic.php?p=2178009&sid=876222db25ab13214a3729dbe1e494b6</a>
* <p>
* The code has been modified by Eric to:
* <ol>
* <li>Work with the current version of hibernate since Dialect.NO_BATCH no longer exists</li>
* <li>Be placed in a different package (org.hibernate.unsupported.dialect) so nobody gets the idea
* that this is actively supported by hibernate or anybody for that matter.  <b>USE AT YOUR OWN RISK...</b></li>
* </ol>
*/
public class MSAccessDialect
extends Dialect {

        public MSAccessDialect() {
                super();
                registerColumnType( Types.BIT, "BIT" );
                registerColumnType( Types.BIGINT, "INTEGER" );
                registerColumnType( Types.SMALLINT, "SMALLINT" );
                registerColumnType( Types.TINYINT, "BYTE" );
                registerColumnType( Types.INTEGER, "INTEGER" );
                registerColumnType( Types.CHAR, "VARCHAR(1)" );
                registerColumnType( Types.VARCHAR, "VARCHAR($l)" );
                registerColumnType( Types.FLOAT, "DOUBLE" );
                registerColumnType( Types.DOUBLE, "DOUBLE" );
                registerColumnType( Types.DATE, "DATETIME" );
                registerColumnType( Types.TIME, "DATETIME" );
                registerColumnType( Types.TIMESTAMP, "DATETIME" );
                registerColumnType( Types.VARBINARY, "VARBINARY($l)" );
                registerColumnType( Types.NUMERIC, "NUMERIC" );

                getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, "0");
        }

        public String getIdentityColumnString() {
                //return " counter ";
                return "not null auto_number";
        }

        public String getIdentitySelectString() {
                return "select @@IDENTITY";
        }


        /**
         * Returns for update syntax for access, which is non-existant, so I *think*
         * we return an empty string...
         * @return String an beautifully constructed empty string...
         */
        public String getForUpdateString() {
                return "";
        }
}


Top
 Profile  
 
 Post subject: Re: MS Access Dialect - supporting Identity column issue
PostPosted: Fri Sep 24, 2010 1:44 am 
Newbie

Joined: Thu Sep 23, 2010 6:27 am
Posts: 3
Hi,

I am new to hibernate technology.I am trying to use Ms-access database with hibernate.For that i created a new MSAccessDialect class by extending Dialect but iam getting a error message saying MSAccessDialect is not found when i run the code.
I dont know where to keep this class.I created a package org.hibernate.dialect in my project and put the MSAccessDialect class there.Also i tried to put the MSAccessDialect in Jboss server org.hibernate.dialect package as .class file.Still i am getting the same error.Please kindly help me where to keep this MSAccessDialect java file so that my JVM can find it.Also tell me the configuration for the hibernate.cfg.xml file.

Thanks and regards,
shalini


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.