Oracle同义词的JPA/Hibernate LocalSessionFactory映射 [英] JPA/Hibernate LocalSessionFactory mapping of Oracle Synonyms

查看:174
本文介绍了Oracle同义词的JPA/Hibernate LocalSessionFactory映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力将Oracle同义词映射到JPA实体中.

I'm struggling with mapping Oracle synonyms into JPA Entities.

作为背景,我需要在tomcat 7服务器以及JBoss EAP 6.4上都使其成为可能. 在下面,您将找到我的持久性配置的摘要.

As a background I'll say, that I need to make it possible either on tomcat 7 server as well as on JBoss EAP 6.4. Below, you'll find a snippet of my persistence configuration.

  1. 数据源查找(找到jndi,已绑定数据源)

@Bean
public DataSource datasource() throws NamingException{
    Context initCtx = new InitialContext();
    Context envCtx = (Context) initCtx.lookup("java:comp/env");
    DataSource ds = (DataSource) envCtx.lookup("jdbc/PAMGODW_DS");

    return ds;
}

  1. LocalSessionFactoryBean(似乎可以正常工作):

@Bean
public LocalSessionFactoryBean sessionFactory() throws NamingException, IOException{
    Properties props = new Properties();
    props.put("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
    props.put("hibernate.synonyms", "true");
    props.put("hibernate.connection.includeSynonyms", "true");


    LocalSessionFactoryBean f = new LocalSessionFactoryBean();
    f.setDataSource(datasource());
    f.setPackagesToScan(new String[]{"com.roche.nrimini.pam.domain.entity", "com.roche.nrimini.pam.domain.service", "com.roche.nrimini.pam.domain.repository"});
    f.setHibernateProperties(props);
    f.setJtaTransactionManager(jtaTransactionManager());
    f.setAnnotatedPackages(new String[]{"com.roche.nrimini.pam.domain.entity", "com.roche.nrimini.pam.domain.service", "com.roche.nrimini.pam.domain.repository"});
    f.afterPropertiesSet();
    System.out.println("LOCALSESSIONFACTORY BEAN");

    return f;}

  1. JtaTransactionManager(似乎也不错):

@Bean
public TransactionManager jtaTransactionManager(){
    JtaTransactionManager manager = new JtaTransactionManager();

    return manager.getTransactionManager();
}

  1. @Table(name ="V_TABLE_SYN")实体实际上指向Oracle同义词:

@Entity
@Table(name = "V_TABLE_SYN")
public class SomeSynonym implements Serializable {

// @Id and @Column mappings here

当我尝试查询实体对象时得到的是ORA-00942表或视图不存在.

What I get, when I try to query for Entity objects is ORA-00942 Table or view does not exist.

在JBoss环境中,standalone.xml中的数据源配置如下:

In JBoss environment, my Datasource config in standalone.xml is like that:

<datasource jta="false" jndi-name="java:jboss/PAMGODW_DS" pool-name="PAMGODW_DS" enabled="true" use-ccm="false">
                <connection-url>jdbc:oracle:thin:@someserver/some_service</connection-url>
                <driver-class>oracle.jdbc.OracleDriver</driver-class>
                <connection-property name="includeSynonyms">
                    true
                </connection-property>
                <driver>oracle</driver>
                <pool>
                    <min-pool-size>0</min-pool-size>
                    <max-pool-size>10</max-pool-size>
                </pool>
                <security>
                    <user-name>some_user</user-name>
                    <password>a_pass</password>
                </security>
                <validation>
                    <validate-on-match>false</validate-on-match>
                    <background-validation>false</background-validation>
                </validation>
                <statement>
                    <share-prepared-statements>false</share-prepared-statements>
                </statement>
            </datasource>

在Tomcat中,我得到了:

In Tomcat, I got :

<Resource name="jdbc/SOME_DS" auth="Container"
          type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
          url="jdbc:oracle:thin:@some_server/some_service"
          username="some_user" password="a_pass" maxActive="20" maxIdle="10"
          maxWait="-1">

我听说过并了解include.synonyms属性,但是它似乎不起作用,在Tomcat env中,我不知道如何设置它.

I've heard and read about include.synonyms property, but it seems not to work, and in Tomcat env, I got no clue how to set it.

请帮助,也许你们中有些人也有类似的问题.

Please help, maybe some of you have had similar issue.

推荐答案

我设法使其正常运行.也许有人会发现它有用.似乎除了无法验证oracle同义词外,还必须设置hibernate.hbm2ddl.auto属性.如您在上一篇文章中所见,我根本没有设置此属性.干杯!

I managed to make it work. Maybe someone will find it useful. It seems that beside the fact that oracle synonyms can't be validated, setting hibernate.hbm2ddl.auto property is mandatory. As you can see in previous post, I haven't had this property set at all. Cheers!

这篇关于Oracle同义词的JPA/Hibernate LocalSessionFactory映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆