如何在 JPA 配置中设置默认模式名称? [英] How to set up default schema name in JPA configuration?

查看:27
本文介绍了如何在 JPA 配置中设置默认模式名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在休眠配置文件中我们可以设置参数hibernate.default_schema:

I found that in hibernate config file we could set up parameter hibernate.default_schema:

<hibernate-configuration> 
   <session-factory>
      ...
      <property name="hibernate.default_schema">myschema</property>
      ...
   </session-factory>
</hibernate-configuration>

现在我正在使用 JPA,我也想这样做.否则我必须将参数 schema 添加到每个 @Table 注释中,例如:

Now I'm using JPA and I want to do the same. Otherwise I have to add parameter schema to each @Table annotation like:

@Entity
@Table (name = "projectcategory", schema = "SCHEMANAME")
public class Category implements Serializable { ... }

据我所知,这个参数应该在这部分配置的某个地方:

As I understand this parameter should be somewhere in this part of configuration:

<bean id="domainEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="JiraManager"/>
    <property name="dataSource" ref="domainDataSource"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="generateDdl" value="false"/>
            <property name="showSql" value="false"/>
            <property name="databasePlatform" value="${hibernate.dialect}"/>
        </bean>
    </property>
</bean>

<bean id="domainDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${db.driver}" />
    <property name="jdbcUrl" value="${datasource.url}" />
    <property name="user" value="${datasource.username}" />
    <property name="password" value="${datasource.password}" />
    <property name="initialPoolSize" value="5"/>
    <property name="minPoolSize" value="5"/>
    <property name="maxPoolSize" value="15"/>
    <property name="checkoutTimeout" value="10000"/>
    <property name="maxStatements" value="150"/>
    <property name="testConnectionOnCheckin" value="true"/>
    <property name="idleConnectionTestPeriod" value="50"/>
</bean>

...但我在谷歌中找不到它的名字.有什么想法吗?

... but I can't find its name in google. Any ideas?

推荐答案

也不知道 JPA 属性.但是您可以将 Hibernate 属性(假设您使用 Hibernate 作为提供者)添加为

Don't know of JPA property for this either. But you could just add the Hibernate property (assuming you use Hibernate as provider) as

...

<property name="hibernate.default_schema" value="myschema"/>

...

Hibernate 应该能解决这个问题

Hibernate should pick that up

这篇关于如何在 JPA 配置中设置默认模式名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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