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

ぃ、小莉子 提交于 2020-01-04 13:43:21

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/14962519/is-there-a-means-by-which-to-configure-hibernate-dialect-based-on-jta-data-sourc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!