-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Multitenancy Schema
PostPosted: Fri Jul 12, 2013 1:37 pm 
Newbie

Joined: Thu Jul 11, 2013 5:08 pm
Posts: 1
Dear, I want to implement multitenancy with hibernate, a database with multiple schemas.
The schemas have to be changed according to the user login.

Currently I am using Hibernate with Spring-data-jpa.
Any suggestions on how to proceed?

persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
   xmlns="http://java.sun.com/xml/ns/persistence">
   <persistence-unit name="persistence">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
         <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/vraptorspringdatajpa" />
         <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
         <property name="hibernate.connection.username" value="root" />
         <property name="hibernate.connection.password" value="root" />
         
         <property name="hibernate.hbm2ddl.auto" value="update" />
         <property name="hibernate.show_sql" value="true" />
         <property name="hibernate.format_sql" value="true" />
         <property name="hibernate.connection.autoReconnect" value="true" />
         <property name="hibernate.connection.autoReconnectForPools" value="true" />
         
         <!-- C3p0 -->
         <property name="hibernate.c3p0.acquire_increment" value="1" />
         <property name="hibernate.c3p0.idle_test_period" value="100" />
         <property name="hibernate.c3p0.timeout" value="100" />
         <property name="hibernate.c3p0.max_size" value="100" />
         <property name="hibernate.c3p0.max_statement" value="0" />
         <property name="hibernate.c3p0.min_size" value="10" />
      </properties>
   </persistence-unit>
</persistence>


applicationContext.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:jpa="http://www.springframework.org/schema/data/jpa"
   xmlns:context="http://www.springframework.org/schema/context"
   
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        classpath:org/springframework/context/config/spring-context-3.0.xsd
        http://www.springframework.org/schema/data/jpa
        classpath:org/springframework/data/jpa/repository/config/spring-jpa-1.0.xsd
        http://www.springframework.org/schema/tx
        classpath:org/springframework/transaction/config/spring-tx-3.0.xsd">

   <context:annotation-config />
   
       <context:component-scan base-package="br.com.vraptor.*" />
   <jpa:repositories base-package="br.com.vraptor.repository" />
   

   <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml"/>
        <property name="persistenceUnitName" value="persistence" />
        <property name="jpaVendorAdapter">
         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="generateDdl" value="true" />
            <property name="database" value="MYSQL" />
            <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
         </bean>
      </property>
    </bean>
   

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />
</beans>



Code:
@Autowired
public ClienteRepository cliente;

public void salvar(Cliente cliente) {
    clienteRepository.save(cliente);
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.