Olá,
Estou tendo dificuldades ao usar JPA com duas conexões abertar simultâneas para o mesmo Banco de Dados. Quero criar dois EntityManagerFactory’s, cada um conectado a um usuário distinto do BD. Utilizei o seguinte código
EntityManagerFactory emf1;
EntityManagerFactory emf2;
Map<String, String> configOverrides;
configOverrides = new HashMap<String, String>();
configOverrides.put("hibernate.connection.username", "user1");
configOverrides.put("hibernate.connection.password", "1234");
emf1 = Persistence.createEntityManagerFactory(
"jurisprudenciaPersistenceUnit", configOverrides);
configOverrides = new HashMap<String, String>();
configOverrides.put("hibernate.connection.username", "user2");
configOverrides.put("hibernate.connection.password", "4321");
emf1 = Persistence.createEntityManagerFactory(
"jurisprudenciaPersistenceUnit", configOverrides);
Contudo, obtive a seguinte mensagem de erro.
Caused by: org.hibernate.cache.CacheException: Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() between repeated calls to buildSessionFactory. Consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider. Error from ehcache was: Cannot parseConfiguration CacheManager. Attempt to create a new instance of CacheManager using the diskStorePath "C:\DOCUME~1\kurumin\CONFIG~1\Temp\" which is already used by an existing CacheManager. The source of the configuration was classpath.
at org.hibernate.cache.EhCacheProvider.start(EhCacheProvider.java:133)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:180)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1213)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:151)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:205)
Meu persistence.xml é este
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="jurisprudenciaPersistenceUnit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection"
value="class" />
<property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.driver_class"
value="oracle.jdbc.OracleDriver" />
<property name="hibernate.default_schema" value="user1" />
<property name="hibernate.connection.url"
value="jdbc:oracle:thin:@127.0.0.1:1521:DSV" />
<property name="hibernate.connection.username"
value="user1" />
<property name="hibernate.connection.password"
value="1234" />
</properties>
</persistence-unit>
</persistence>
O sistema funciona corretamente para uma única conexão. Alguém poderia me ajudar?