Foros de discusión

RE More DB Connection

thumbnail
Manikantha Rajamani, modificado hace 9 años.

RE More DB Connection

Expert Mensajes: 258 Fecha de incorporación: 25/03/14 Mensajes recientes
Hi Guys

If there are 3 portlets and all of them need to talk to different database systems (say MySQL, Oracle and SQL Server),
How to Achive the multiple DB connection in liferay..


Thanks & regards
Manikantha R
thumbnail
Manali Lalaji, modificado hace 9 años.

RE: RE More DB Connection

Expert Mensajes: 362 Fecha de incorporación: 9/03/10 Mensajes recientes
Hi Manikantha,

The main database will remain same, that is one mentioned in portal-ext.properties

In order to connect to different database:

In your server context.xml(i.e inside tomcat/config/), you can add the database configuration as follows :

<Resource auth="Container" driverClassName="oracle.jdbc.driver.OracleDriver or mysql driver" maxActive="50" maxIdle="30" maxWait="10000" name="xyzDataSource1" password="xxxx" type="javax.sql.DataSource" url="databaseURL" username="uname"/>

You can define multiple data sources as mentioned above.

In service.xml, we need to define datasource for the particular entity we wish to connect to secondary database,
For e.g. <entity name="TestEntity" cache-enabled="false" table="TestTable" local-service="true" data-source="xyzDataSource1">

Also Refer:
http://www.liferaysavvy.com/2013/08/liferay-plugin-portlet-connecting-to.html
http://liferaytrends.blogspot.com/2012/05/connecting-to-different-database-using.html

HTH!
giorgio galassi, modificado hace 9 años.

RE: RE More DB Connection

New Member Mensaje: 1 Fecha de incorporación: 13/10/14 Mensajes recientes
I have a liferat 6.2 with tomcat 7 and postgrs db for liferay data. I 'd like to connect to mantain the actual postgres db for liferay data and use another postgres db for other data. So in my portal-ext.properties i have :
jdbc.default.driverClassName=org.postgresql.Driver
jdbc.default.url=jdbc:postgresql://localhost:5432/liferay
jdbc.default.username=aaaaaaa
jdbc.default.password=aaaaaaaa
jdbc.default.jndi.name=jdbc/LiferayPool

jdbc.tcs.driverClassName=org.postgresql.Driver
jdbc.tcs.url=jdbc:postgresql://localhost:5432/provagiorgio13
jdbc.tcs.username=aaaaaa
jdbc.tcs.password=aaaaaaaa
jdbc.tcs.jndi.name=jdbc/provagiorgio13

in context.xml i have put
<Resource auth="Container"
driverClassName="org.postgresql.Driver"
maxActive="50"
maxIdle="30"
maxWait="10000"
name="jdbc/provagiorgio13"
password="aaaaaaa"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/provagiorgio13"
username="aaaaaaaa"/>

and my service.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<entity name="ScenarioI" cache-enabled="false" table="ScenarioI" local-service="true" data-source="jdbc/provagiorgio13"/>


my persistence.xml is :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="jdbc/provagiorgio13" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>db.Utenti</class>
<class>db.Formarefluo</class>
<class>db.RefluoPK</class>
<class>db.Refluo</class>
<class>db.AlternativaTrattamento</class>
.......
<class>db.Particellescenario</class>
<class>db.DistanzaCentroParticelle</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/provagiorgio13"/>
<property name="javax.persistence.jdbc.user" value="aaaa"/>
<property name="javax.persistence.jdbc.password" value="aaaaa"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
</properties>
</persistence-unit>



</persistence>







In my portlet I have a bean that :

entityManagerFactory = Persistence.createEntityManagerFactory("jdbc/provagiorgio13");
entityManager = getEntityManagerFactory().createEntityManager();
jpa = (JpaEntityManager) entityManager.getDelegate();
serverSession = jpa.getServerSession();

When I place my portlet on a page and refresh the page I obtain the error :
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named jdbc/provagiorgio13

at line entityManagerFactory = Persistence.createEntityManagerFactory("jdbc/provagiorgio13");

I use eclipse ide liferay and to put jpa entities from table in my portlet I have had realize a jpa project that comunicate with persistence eclipselink to my postgres db. So I know that the jpa project is right but I don't know where in my portlet isn't correct or missed.

Thank in advance