Robert Simmons Jr.
Robert Simmons Jr.

Reputation: 1182

Is there a means by which to configure Hibernate Dialect Based on jta-data-source?

Assuming an ejb-jar with the following persistence.xml configuration:

    <?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
  <persistence-unit name="com.mystrotv.mdn.admanager.entity">
    <jta-data-source>/dataSource/MystroDS_Tx</jta-data-source>
    <properties>
      <property name="jboss.entity.manager.jndi.name" value="java:/EntityManagers/AdManagerPersistenceContext"/>
      <property name="jboss.entity.manager.factory.jndi.name" value="java:/EntityManagers/AdManagerPersistenceUnit"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
      <property name="hibernate.hbm2ddl.auto" value="validate"/>
      <property name="hibernate.max_fetch_depth" value="5"/>
      <property name="hibernate.validator.apply_to_ddl" value="false" />
      <property name="hibernate.validator.autoregister_listeners" value="false" />
    </properties>
  </persistence-unit>
</persistence>

I would like to define the hibernate dialect based on the JTA data source. If it is oracle, I use the dialect indicated below, if postgres, I use a different dialect. Does anyone know how to do this or can point me to documentation on how to do it? Google has failed to turn up the needed information. The app will be deployed in a JBoss app server but I want to support other app servers as well. Furthermore, we have two deployment models, one uses postgres and one uses oracle and Id rather not have to build two Ears to support a one line difference in a config file.

Thanks in advance.

Upvotes: 2

Views: 1435

Answers (1)

Robert Simmons Jr.
Robert Simmons Jr.

Reputation: 1182

And just after I post the question, I find the answer;

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#portability-dialectresolver

Specifically, if a dialect is not specified, versions of hibernate from 3.2 on should auto-detect it from the JTA data source and thus the correct procedure is to leave the dialect specification off the properties altogether.

Upvotes: 4

Related Questions