掲示板
Error defining a new datasource with Service Builder
11年前 に Manuel Pastor によって更新されました。
Error defining a new datasource with Service Builder
New Member 投稿: 13 参加年月日: 13/03/05 最新の投稿
Hi, I'm trying to define a different datasource than Liferay's datasource using the Service Builder framework.
The service.xml file contains the references to the new datasource and new session factory:
<namespace>Test</namespace>
<entity name="Admin" local-service="true" remote-service="false" data-source="extDatasource" session-factory="testSessionFactory" tx-manager="testTransactionManager">
Adding a ext-spring.xml file like this:
<?xml version="1.0"?>
<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="extDatasource" lazy-init="true" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:." />
<property name="username" value="SA" />
<property name="password" value="" />
</bean>
<!-- Don't redefining LiferayHibernateSessionFactory: -->
<!-- <bean id="liferayHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource" ref="extDatasource" />
</bean> -->
<bean id="testHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration" lazy-init="true">
<property name="dataSource" ref="extDatasource" />
</bean>
<bean id="testSessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl" lazy-init="true">
<property name="sessionFactoryImplementor" ref="testHibernateSessionFactory" />
</bean>
<bean id="testTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
<property name="dataSource" ref="extDatasource" />
<property name="globalRollbackOnParticipationFailure" value="false"/>
<property name="sessionFactory" ref="testHibernateSessionFactory" />
</bean>
</beans>
But when I do something like this: List<Admin> lProperties = adminPersistence.findAll();
I obtain the next error:
com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: org.hibernate.exception.SQLGrammarException:
could not execute query
...
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2545)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:940)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at com.liferay.portal.dao.orm.hibernate.QueryImpl.list(QueryImpl.java:86)
... 232 more
Caused by: java.sql.SQLException: usuario no tiene privilegios suficientes o objeto no encontrado: TEST_ADMIN
I think that the portlet is using the LiferayHibernateSession that maps with the Liferay's default database and it's ignoring my datasource...
How can I tell by code that before execute that: adminPersistence.findAll(); it uses my session that maps with my external database?
Thanks.
The service.xml file contains the references to the new datasource and new session factory:
<namespace>Test</namespace>
<entity name="Admin" local-service="true" remote-service="false" data-source="extDatasource" session-factory="testSessionFactory" tx-manager="testTransactionManager">
Adding a ext-spring.xml file like this:
<?xml version="1.0"?>
<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="extDatasource" lazy-init="true" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:." />
<property name="username" value="SA" />
<property name="password" value="" />
</bean>
<!-- Don't redefining LiferayHibernateSessionFactory: -->
<!-- <bean id="liferayHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource" ref="extDatasource" />
</bean> -->
<bean id="testHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration" lazy-init="true">
<property name="dataSource" ref="extDatasource" />
</bean>
<bean id="testSessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl" lazy-init="true">
<property name="sessionFactoryImplementor" ref="testHibernateSessionFactory" />
</bean>
<bean id="testTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
<property name="dataSource" ref="extDatasource" />
<property name="globalRollbackOnParticipationFailure" value="false"/>
<property name="sessionFactory" ref="testHibernateSessionFactory" />
</bean>
</beans>
But when I do something like this: List<Admin> lProperties = adminPersistence.findAll();
I obtain the next error:
com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: org.hibernate.exception.SQLGrammarException:
could not execute query
...
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2545)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:940)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at com.liferay.portal.dao.orm.hibernate.QueryImpl.list(QueryImpl.java:86)
... 232 more
Caused by: java.sql.SQLException: usuario no tiene privilegios suficientes o objeto no encontrado: TEST_ADMIN
I think that the portlet is using the LiferayHibernateSession that maps with the Liferay's default database and it's ignoring my datasource...
How can I tell by code that before execute that: adminPersistence.findAll(); it uses my session that maps with my external database?
Thanks.
11年前 に David H Nebinger によって更新されました。
RE: Error defining a new datasource with Service Builder
Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿Manuel Pastor:
Caused by: java.sql.SQLException: usuario no tiene privilegios suficientes o objeto no encontrado: TEST_ADMIN
I think that the portlet is using the LiferayHibernateSession that maps with the Liferay's default database and it's ignoring my datasource...
I think you're assuming that, but I don't know that the assumption is true...
Caused by: java.sql.SQLException: usuario no tiene privilegios suficientes o objeto no encontrado: TEST_ADMIN
It's quite possible that HSQLDB is throwing the exception if you do not have permissions to access the filesystem where the hsql database would be created. It looks like you're trying to define an in-memory database, but I really don't know if that wouldn't also have some sort of filesystem access requirement.
How can I tell by code that before execute that: adminPersistence.findAll(); it uses my session that maps with my external database?
Well, this line actually intrigues me. Where are you putting this line? Is it in AdminLocalServiceImpl, or are you somehow getting to the adminPersistence instance somewhere else?
11年前 に Manuel Pastor によって更新されました。
RE: Error defining a new datasource with Service Builder
New Member 投稿: 13 参加年月日: 13/03/05 最新の投稿
Thanks for the reply.
About that:
The code is:
public class AdminLocalServiceImpl extends AdminLocalServiceBaseImpl {
...
public List<Admin> getAllProperties() throws SystemException {
List<Admin> lProperties = adminPersistence.findAll();
return lProperties;
}
About that:
Well, this line actually intrigues me. Where are you putting this line? Is it in AdminLocalServiceImpl, or are you somehow getting to the adminPersistence instance somewhere else?
The code is:
public class AdminLocalServiceImpl extends AdminLocalServiceBaseImpl {
...
public List<Admin> getAllProperties() throws SystemException {
List<Admin> lProperties = adminPersistence.findAll();
return lProperties;
}
11年前 に David H Nebinger によって更新されました。
RE: Error defining a new datasource with Service Builder
Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Did you rebuild the services after setting the datasource?
Otherwise at this point I'd be getting into the debugger and step through the code...
Otherwise at this point I'd be getting into the debugger and step through the code...
11年前 に Manuel Pastor によって更新されました。
RE: Error defining a new datasource with Service Builder
New Member 投稿: 13 参加年月日: 13/03/05 最新の投稿
Like you told me, I think it could be a problem with the HSQLDB database.
I tried with a java main outside Liferay that executes a query against the hsql database and I obtain the same error:
java.t.SQLSyntaxErrorException: usuario no tiene privilegios suficientes o objeto no encontrado: table_name
I'm going to investigate that way! Thanks.
I tried with a java main outside Liferay that executes a query against the hsql database and I obtain the same error:
java.t.SQLSyntaxErrorException: usuario no tiene privilegios suficientes o objeto no encontrado: table_name
I'm going to investigate that way! Thanks.
11年前 に David H Nebinger によって更新されました。
RE: Error defining a new datasource with Service Builder
Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
So depending upon your environment, you may not have write access to the directory where hsql wants to create the files...