Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up default schema name in JPA configuration?

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> 

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?

like image 709
Roman Avatar asked Apr 29 '10 12:04

Roman


People also ask

How do you set a schema in DataSource?

there is added support for specifying the current schema using URL. With @ClassRule, we create an instance of PostgreSQL database container. Next, in the setup method, create a connection to that database and create the required objects. To change the default schema, we need to specify the currentSchema parameter.

What is @entity annotation in spring boot?

The @Entity annotation specifies that the class is an entity and is mapped to a database table. The @Table annotation specifies the name of the database table to be used for mapping.


1 Answers

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 should pick that up

like image 140
bert Avatar answered Sep 20 '22 09:09

bert