Pau Ruiz

Greenhorn
+ Follow
since Nov 15, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pau Ruiz

Jagdish Gahlot wrote:hi Christian.. thanks for your help, your example is completely working but i have one situation where i don't want to declare 2 persistence entity factory bean (LocalContainerEntityManagerFactoryBean) rather than i want to use single persistence factory dealing with multiple PUs which in turn will use multiple Datasources. i tried lots of option but couldn't get.

Is there a way that we can declare one single bean of LocalContainerEntityManagerFactoryBean which will be defining 1 PersistenceUnitManager and that PersistenceUnitManager will define a list of datasources. then how my DAO will use these Datasources (either of them at a time) ? also in persistence.xml file i will define 2 persistence unit name bt how there PU name will be linked with datasources defined in my applicationContext.xml 's datasources. i hope everyone is getting what i mean to say exactly.

please help.



If you define 2 LocalContainerEntityManagerFactoryBean, are not you the exception?
8 years ago
I've tried setting the example and I have not been successful.

First I created just such a connection using connection pooling with Atomikos and it worked.

But when I went to put my second connection, to put another LocalContainerEntityManagerFactoryBean have always been the exception:



I do not know where the problem is, can you put the code of your persistence-XXX.xml and xxx.xxx.xxx.JtaPersistenceUnitPostProcessor? To see if there is the problem.

On the other hand, I always use org.apache.commons.dbcp.BasicDataSource connection pool, do you advise using Atomik better?
8 years ago
Ah ok, I understand. Well I try and tell you something, thank you very much again!.
8 years ago
Thank you very much, when can I try and explain the result.

But I have a question, do I have to declare all the DAO to inject EntityManager even use annotations?
8 years ago

Vyas Sanzgiri wrote:I just see one datasource in the configuration file you posted. Can you please post the complete file with 2 data sources and the exception ? It looks as if you are naming both beans entityManagerFactory. Try changing the name





And the exception:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2
8 years ago
I have a problem connecting more than one database, I have spent 2 days without succes. I have read through different forums without getting results. I do not understand how something as simple as connecting to two databases so difficult when using Spring + JPA + Hibernate.

I need two datasource and can make transactions between them. I put my settings for only one connection.



I read that you could create two LocalContainerEntityManagerFactoryBean, this always gives an exception in the application startup:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2

And I think if I have also created two EntityManagerFactory to create two JpaTransactionManager and that's not the goal.

In my search for internet or watching Spring documentation to create multiple persistence units must be used org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager, I've tried without success, how to tell the DAO datasource to use?

In other post I read said that Spring with JPA can only connect to a datasource to connect to more than one is to use JNDI, is that true?

I am new to Spring and whether the approach has to be one or it is advisable to use JNDI, I'm open to suggestions.

Whatever it takes to complete the information you just have to ask.

Thank you very much!
8 years ago