Foros de discusión

Is it possible to push data into non-liferay database using service.xml

Pavan Gupta, modificado hace 11 años.

Is it possible to push data into non-liferay database using service.xml

New Member Mensajes: 16 Fecha de incorporación: 28/08/12 Mensajes recientes
Hi,

I am using liferay 6.1 to build a portlet. My requirement is to fetch data from non-liferay DB and update entries (push entries) back to non-liferay DB.

Using service builder tool, i am able to fetch data from non-LR DB but while pushing data back to non-LR DB, my portlet is trying to find table in LR DB and throwing table didn't exist exception.

So is it possible to push data back to Non-LR DB using service builder tool?

Thanks,
Pavan
thumbnail
Christianto Sahat, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

Regular Member Mensajes: 179 Fecha de incorporación: 25/09/07 Mensajes recientes
I believe you just need to specify different datasource in service.xml, instead of Liferay's datasource ?
Pavan Gupta, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

New Member Mensajes: 16 Fecha de incorporación: 28/08/12 Mensajes recientes
Hi Christianto,

Thanks for the response. Following entity info, i ahave specified in my service.xml content:


<entity name="Training" local-service="true" table="training"
remote-service="true" data-source="myDatasource">
<column name="userId" type="long" primary="true"></column>
<column name="firstName" type="String"></column>
<column name="lastName" type="String"></column>
</entity>


and non-LR DB info is present in ext-spring.xml file.

Fetching data is working fine but i am facing problem while pushing data to non-LR DB..

Thanks,
Pavan
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
Rather than writing about generalities that is anyone's guess, how about trying some specifics, i.e "when I call updateXxxx() it fails w/ this exception and here's the stack trace"...
Pavan Gupta, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

New Member Mensajes: 16 Fecha de incorporación: 28/08/12 Mensajes recientes
@Christianto,
As i mentioned above, i have specified custom data-source "myDatasource" in service.xml file. Custom datasource info (connection url, username and passwd) is declared in ext-spring.xml file.

David H Nebinger:
Rather than writing about generalities that is anyone's guess, how about trying some specifics, i.e "when I call updateXxxx() it fails w/ this exception and here's the stack trace"...


@David, I am not getting any stack trace. it is printing only one line "ERROR [JDBCExceptionReporter:75] Table 'lportal.training' doesn't exist" on console.
i have a table name training in my Non-LR DB. and when i call addTraining(training modelObj), it is printing "lportal.training' doesn't exist" on console.
thumbnail
Christianto Sahat, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

Regular Member Mensajes: 179 Fecha de incorporación: 25/09/07 Mensajes recientes
Seems that your configuration still using Liferay's datasource instead your own database.

Check out this link for your reference :
http://www.liferay.com/web/sten.martinez/blog/-/blogs/6831821
http://www.manning-sandbox.com/thread.jspa?threadID=40188
http://www.liferay.com/community/wiki/-/wiki/Main/Build+Services+Against+External+Database
http://www.liferay.com/community/wiki/-/wiki/Main/Connect+to+a+Database+with+Plugins+SDK

Another person that has successfully solve your problem :
http://www.liferay.com/community/forums/-/message_boards/message/12122420
anand gopalan, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

Expert Mensajes: 442 Fecha de incorporación: 2/03/12 Mensajes recientes
Hi Pavan,

My requirement is like you only, i want to fetch the data from existing table.
i am using liferay6.1.0 CE and mysql 5.5

I created new portlet for view the Page.
please tell me what to define in service.xml for only fetch the data from my employee table.

using some condition.

(or)
you can tell only how to fetch the data from the employee table. using service.xml or any other possible way.

your information is very helpful for me. please send
Pavan Gupta, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

New Member Mensajes: 16 Fecha de incorporación: 28/08/12 Mensajes recientes
Hi Anand,

service.xml only generates persistence layer code for you. If you want to fetch data from external DB then you need to create ext-spring.xml file and specify external Datasource info, hibernate session factory info in that config file. Put that config file in Meta-inf folder where other hibernate, spring related config files are present.

Here is my ext-spring.xml files content:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="myDatasource" lazy-init="true" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/training?useUnicode=true"/>
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="liferayHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource" ref="myDatasource" />
</bean>
</beans>

i guess, this will help u.

Thanks,
Pavan
anand gopalan, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

Expert Mensajes: 442 Fecha de incorporación: 2/03/12 Mensajes recientes
i created ext-spring.xml now where i can place, I am using eclipse for Liferay and using portlet.
anand gopalan, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

Expert Mensajes: 442 Fecha de incorporación: 2/03/12 Mensajes recientes
Hello Pavan,
i created ext-spring.xml and place into liferay-plugins-sdk-6.1.0-ce-ga1\portlets\empform-portlet\docroot\WEB-INF\src\META-INF\ext-spring.xml

Till now,

I created a new portlet using eclipse - liferay6.1.0 and it generate default some files.
Now I created ext-spring.xml.

Now, Please tell what is the next step I want to do.

Please guide me & already I am running out of time.

Regards
Anand
Pavan Gupta, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

New Member Mensajes: 16 Fecha de incorporación: 28/08/12 Mensajes recientes
Hi Anand,

Define External DB table schema in service.xml and generate code using service builder.

this is my service.xml file content.

<entity name="Training" local-service="true" table="training"
remote-service="true" data-source="myDatasource">
<column name="userId" type="long" primary="true"></column>
<column name="firstName" type="String"></column>
<column name="lastName" type="String"></column>
</entity>

By using generated service, u should able to access external tables.

Thanks,
Pavan
anand gopalan, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

Expert Mensajes: 442 Fecha de incorporación: 2/03/12 Mensajes recientes
thank you pavan, I modify my service.xml and build services.

now how i fetch the record in view.jsp
anand gopalan, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

Expert Mensajes: 442 Fecha de incorporación: 2/03/12 Mensajes recientes
which class i need to import to get the empid,employee name,...........etc

pavan send your input
Pavan Gupta, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

New Member Mensajes: 16 Fecha de incorporación: 28/08/12 Mensajes recientes
Hi,

After generating persistence layer code, u must be having some utility class related to ur service. Use that utility class to fetch data from DB.

Thanks,
Pavan
anand gopalan, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

Expert Mensajes: 442 Fecha de incorporación: 2/03/12 Mensajes recientes
Hi Paven,

I have attached Employee portlet file. I sent my all code. I have written view.jsp to call util class to fetch the record from the employee table.

Can you please correct me where I am doing wrong in view.jsp. Because in the persistance class set all the employee details using SOAP and other place using JSON.

so I got confuse how to get the employee table record. Please correct me. it will really help for me.

Archivos adjuntos:

anand gopalan, modificado hace 11 años.

RE: Is it possible to push data into non-liferay database using service.xml

Expert Mensajes: 442 Fecha de incorporación: 2/03/12 Mensajes recientes
In ext-spring.xml

<bean id="liferayHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource" ref="myDatasource" />

com.liferay.portal.spring.hibernate.PortletHibernateConfiguration - I didn't create any class.

Please tell me what i need to do.