小编典典

如何在JPA配置中设置默认架构名称?

hibernate

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

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

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

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

据我了解,此参数应该在配置的这一部分中:

<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>

…但是我在Google中找不到它的名字。有任何想法吗?


阅读 221

收藏
2020-06-20

共1个答案

小编典典

也不知道为此的JPA属性。但是,您可以仅将Hibernate属性(假设您使用Hibernate作为提供程序)添加为

...

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

...

hibernate应该接起来

2020-06-20