2 Replies Latest reply on Aug 29, 2008 10:08 AM by Robert

    How do I set hibernate.dialect property outside of persisten

    Robert Newbie

      Hi,

      We are deploying an application on JBoss and we would like to give our customers the ability to choose which database (Oracle, MySQL, etc.) they would like to use. It's fairly easy to have the installer lay down a customized ds.xml file in the deploy folder to define the chosen data source; however, we're getting hung up with setting the hibernate.dialect property in the persistence.xml file. For example, if our customer decides that they would like to use MySQL, then we would need the following line in persistence.xml:

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


      Of course, we could have the installer unzip our ear file, unzip the jar file and modify the persistence.xml file, but we were wondering if there was a cleaner way of setting this property. Is there an external configuration option that can be used to set a property for a persistence-unit? For example, could I modify something like the persistence.properties file?

      Any help would be greatly appreciated.

        • 1. Re: How do I set hibernate.dialect property outside of persi
          Robert Newbie

          By the way, we're using JBoss 4.2.2.GA.

          • 2. Re: How do I set hibernate.dialect property outside of persi
            Robert Newbie

            It seems that it is not necessary to set this "hibernate.dialect" property. The correct dialect is chosen by the framework at run-time. For example, if I have a mysql-ds.xml file with the following contents:

            <datasources>
             <local-tx-datasource>
             <jndi-name>MyDS</jndi-name>
             <connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
             <driver-class>com.mysql.jdbc.Driver</driver-class>
             ...
             <metadata>
             <type-mapping>mySQL</type-mapping>
             </metadata>
             </local-tx-datasource>
            </datasources>
            


            ... then I receive the following output in the console:

            [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
            [InjectedDataSourceConnectionProvider] Using provided datasource
            [SettingsFactory] RDBMS: MySQL, version: 5.0.51b-community-nt
            [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
            [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
            


            Note that, if you don't include the database driver in deploy/lib, JBoss will throw an exception reporting that the hibernate dialect must be set. We made this mistake and the exception lead us to believe that we had to set the "hibernate.dialect" property.