留言板

ServiceBuilder with external DS - DS not being used in some cases?

Ramon Ernesto Villen Souviron,修改在11 年前。

ServiceBuilder with external DS - DS not being used in some cases?

New Member 帖子: 2 加入日期: 13-1-17 最近的帖子
Hi,

we have developed an intranet portal using liferay-portal-6.1.1-ce-ga2. Requirements included the creation of a custom service to access our client's external database.

So, we created this service using ServiceBuilder, Manning "Liferay in Action" book as a guide and Liferay 6.1 API docs.

We have defined our custom datasource in src/META-INF/ext-spring.xml.
We stablished custom hibernateSessionFactory and TransactionManager, both referencing our custom datasource.
Then, we set our custom entities "DataSource", "Session Factory" and "Tx Manager" attributes to the ones defined in ext-spring.xml
Finally, we implemented custom Finders with custom SQL.

After building the service and deploying it (no errors or warnings) we notice that under certain circumstances our service uses Liferay default DS (accesing lportal), while the rest of the time our custom DS is used. We have identified the following scenarios where the described behaviour is consistent:

1) Jboss always deploys the database tables to 'lportal' instead of our custom DB.
2) when using a default LocalServiceUtil method, such as exampleLocalServiceUtil.getExamples(-1, -1) to get a full list of 'examples', the service looks in lportal database.
3) when using one of our custom Finder methods, such as customExampleLocalServiceUtil.getExamples(-1,1), the service looks up our 'custom' database.
4) when performing update operations using the service default methods, 'custom' database is used.

What could be causing this?
Thanks in advance
thumbnail
David H Nebinger,修改在11 年前。

RE: ServiceBuilder with external DS - DS not being used in some cases?

Liferay Legend 帖子: 14916 加入日期: 06-9-2 最近的帖子
If you add a service-ext.properties file, you can set build.auto.upgrade=false which will prevent the tables from being created in liferay's database.

As to why it may be using the LR datasource, not sure. When you say:

Then, we set our custom entities "DataSource", "Session Factory" and "Tx Manager" attributes to the ones defined in ext-spring.xml


I'm guessing that you actually meant that, in the service.xml file, your entities are defined like:

 <entity ... data-source="myDataSource" session-factory="mySessionFactory" tx-manager="myTxnManager">...</entity>
Ramon Ernesto Villen Souviron,修改在11 年前。

RE: ServiceBuilder with external DS - DS not being used in some cases?

New Member 帖子: 2 加入日期: 13-1-17 最近的帖子
If you add a service-ext.properties file, you can set build.auto.upgrade=false which will prevent the tables from being created in liferay's database.


Added this now, thanks!

I'm guessing that you actually meant that, in the service.xml file, your entities are defined like: ...


Yep, that's what I meant.

Thanks!
Chris Tophe,修改在11 年前。

RE: ServiceBuilder with external DS - DS not being used in some cases?

New Member 发布: 1 加入日期: 13-2-1 最近的帖子
Hello,

I tried to use custom sql with custom DS. I only change references to Datasource in ext-spring.xml but I use the default SessionFactory and transaction tx beacause I can't find on the net a description of how to do to customize these objects.

My configuration works when I use service buildes standard methods (with the external database) but When I want to use custom sql I have an error (the bean names with my datasource can't be created).


Is ther somewher a description of how to configure Liferay to do custom sql on external DS ?

Thanks a lot
Christophe