论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Ohad Raz
Service Builder With Custom DataSource Breaks Hot Deploy
2013年1月17日 上午3:43
答复

Ohad Raz

等级: New Member

帖子: 23

加入日期: 2012年6月27日

最近的帖子

Hi,

I have created a simple service builder that uses a custom data source.
As a result, the hot-deploy functionality got broken.
When trying to hot-deploy the following exception appears in the server's log:

com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: java.lang.IllegalStateException: The com.liferay.portal.model.impl.CompanyImpl Cache is not alive.
com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: java.lang.IllegalStateException: The com.liferay.portal.model.impl.CompanyImpl Cache is not alive.
at com.liferay.portal.service.persistence.impl.BasePersistenceImpl.processException(BasePersistenceImpl.java:190)
at com.liferay.portal.service.persistence.CompanyPersistenceImpl.fetchByPrimaryKey(CompanyPersistenceImpl.java:488)
at com.liferay.portal.service.persistence.CompanyPersistenceImpl.findByPrimaryKey(CompanyPersistenceImpl.java:432)
at com.liferay.portal.service.impl.CompanyLocalServiceImpl.getCompanyById(CompanyLocalServiceImpl.java:461)
at sun.reflect.GeneratedMethodAccessor219.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
...

(The same exception repeats for all kind of Liferay's objects, not necessary the Company alone, e.g., Layout).

I have built my service builder based on the tips in the following blog:
http://www.liferay.com/about-us/privacy/-/blogs/6831821/maximized
It all seemed to work, but when I tried to hot-deploy, the aforementioned exceptions were observed.

My service.xml looked as follows:
 1<?xml version="1.0" encoding="UTF-8"?>
 2<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN"
 3          "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
 4
 5<service-builder package-path="com.company.project.entity" auto-namespace-tables="true">
 6   <author><![CDATA[<a href="ohad.raz@orbitz.com">Raz, Ohad</a>]]></author>
 7
 8   <namespace>entity</namespace>
 9   <entity name="Entity"
10           local-service="true"
11           human-name="Entities"
12           table="TB_ENTITY"
13           data-source="company-project-DS"
14           session-factory="company-project-SessionFactory"
15           tx-manager="company-project-TransactionManager">
16
17      <!-- PK fields -->
18      <column db-name="TB_ENTITY_ID" name="entityID" primary="true" type="long" />
19
20      <!-- Audit fields -->
21      <column db-name="CREATE_DATE" name="createDate" type="Date" />
22      <column db-name="MODIFIED_DATE" name="modifiedDate" type="Date" />
23
24      <!-- Other fields -->
25      <column db-name="COLUMN_A" name="columnA" type="long" />
26      <column db-name="COLUMN_B" name="columnB" type="String" />
27      <column db-name="COLUMN_C" name="columnC" type="Date" />
28
29      <!-- Finder methods -->
30      <finder name="ColumnA" return-type="Entity">
31         <finder-column name="columnA" />
32      </finder>
33   </entity>
34</service-builder>

And my ext-spring.xml looked as follows:
 1<?xml version="1.0" encoding="UTF-8"?>
 2
 3<beans xmlns="http://www.springframework.org/schema/beans"
 4        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 6
 7   <bean id="company-project-SessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl" lazy-init="true">
 8      <property name="sessionFactoryImplementor">
 9         <bean class="com.liferay.portal.spring.hibernate.PortalHibernateConfiguration" lazy-init="true">
10            <property name="dataSource">
11               <ref bean="company-project-DS" />
12            </property>
13            <property name="mappingResources">
14               <list>
15                  <value>META-INF/portlet-hbm.xml</value>
16               </list>
17            </property>
18         </bean>
19      </property>
20   </bean>
21
22   <bean id="company-project-DS" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" lazy-init="true">
23      <property name="targetDataSource">
24         <bean class="com.liferay.portal.spring.jndi.JndiObjectFactoryBean" lazy-init="true">
25            <property name="jndiName">
26               <value>jdbc/CompanyProjectData</value>
27            </property>
28         </bean>
29      </property>
30   </bean>
31
32   <bean id="company-projec-TransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
33      <property name="dataSource">
34         <ref bean="company-projec-DS" />
35      </property>
36      <property name="sessionFactory">
37         <ref bean="company-projec-SessionFactory" />
38      </property>
39   </bean>
40</beans>


So, where was the problem?
Ohad Raz
RE: Service Builder With Custom DataSource Breaks Hot Deploy
2013年1月17日 上午4:23
答复

Ohad Raz

等级: New Member

帖子: 23

加入日期: 2012年6月27日

最近的帖子

So, I have came across the following thread:
http://www.liferay.com/community/forums/-/message_boards/message/13076583
which, in its turn, points to http://www.liferay.com/community/forums/-/message_boards/message/10713975.
So I realized that the problem is that I have used com.liferay.portal.spring.hibernate.PortalHibernateConfiguration as the Session Factory Implementor.
I looked at the source code of this class, and indeed it seems to be messing Liferay's internals, and should be used for custom data sources and entities.
So, I tried the suggestions in the aforementioned thread, using org.springframework.orm.hibernate3.LocalSessionFactoryBean as the Session Factory Implementor.
But then I kept getting org.hibernate.HibernateException: Unable to get the default Bean Validation factory exception.
I googled it, and found that I had to add a hibernate-validator.jar to my classpath.
I have tried several jars, of different versions, but nothing helped.
I finally found the properties needed to disable the validator, but then I got exceptions about cache - either enabling, it, or missing provider...
Another google, and...
Eureka!
It all works! Liferay starts up with no exceptions, it runs fine, and I can hot-deploy!!!

What's changed?

Well, this is the ext-spring.xml that made it all to work:
 1<?xml version="1.0" encoding="UTF-8"?>
 2<beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 5
 6   <bean id="company-project-SessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl" lazy-init="true">
 7      <property name="sessionFactoryImplementor">
 8         <bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" lazy-init="true">
 9            <property name="configurationClass">
10               <value>org.hibernate.cfg.Configuration</value>
11            </property>
12            <property name="dataSource">
13               <ref bean="company-project-DS" />
14            </property>
15            <property name="mappingResources">
16               <list>
17                  <value>META-INF/portlet-hbm.xml</value>
18               </list>
19            </property>
20            <property name="hibernateProperties">
21               <props>
22                  <prop key="hibernate.validator.apply_to_ddl">false</prop>
23                  <prop key="hibernate.validator.autoregister_listeners">false</prop>
24                  <prop key="javax.persistence.validation.mode">none</prop>
25                  <prop key="hibernate.cache.use_second_level_cache">true</prop>
26                  <prop key="hibernate.cache.use_query_cache">true</prop>
27                  <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
28               </props>
29            </property>
30         </bean>
31      </property>
32   </bean>
33
34   <bean id="company-project-DS" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" lazy-init="true">
35      <property name="targetDataSource">
36         <bean class="com.liferay.portal.spring.jndi.JndiObjectFactoryBean" lazy-init="true">
37            <property name="jndiName">
38               <value>jdbc/CompanyProjectData</value>
39            </property>
40         </bean>
41      </property>
42   </bean>
43
44   <bean id="company-project-TransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
45      <property name="dataSource">
46         <ref bean="company-project-DS" />
47      </property>
48      <property name="sessionFactory">
49         <ref bean="company-project-SessionFactory" />
50      </property>
51   </bean>
52</beans>


Hope it can help anyone encountering the same problems...

Cheers,
Ohad
David H Nebinger
RE: Service Builder With Custom DataSource Breaks Hot Deploy
2013年1月17日 上午6:07
答复

David H Nebinger

Community Moderator

等级: Liferay Legend

帖子: 11793

加入日期: 2006年9月1日

最近的帖子

Not sure what you've used, but here's how I define external db connections...

 1
 2 <bean id="myDataSource" lazy-init="true" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
 3    ....
 4 </bean>
 5 <bean id="myHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
 6    <property name="dataSource" ref="myDataSource" />
 7    ....
 8 </bean>
 9 <bean id="mySessionFactory" class="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl">
10    <property name="dataSource" ref="myDataSource" />
11    <property name="sessionFactoryClassLoader" ref="portletClassLoader" />
12    <property name="sessionFactoryImplementor" ref="myHibernateSessionFactory" />
13 </bean>


This way I'm still using all Liferay entities (don't know if it's necessary, but maximizes compatibility).

Also I don't need to define anything for transaction handling (the default Liferay transaction handling has been good enough).

As far as hibernate validator was concerned, I too had to add it, but version 4.3.0 worked just fine. Needed the hibernate-validator-4.3.0.Final.jar and hibernate-validator-annotation-processor-4.3.0.Final.jar in my lib folder, but had no version issues to deal with.

And I didn't have to disable the cache!
Konstantin Chudinov
RE: Service Builder With Custom DataSource Breaks Hot Deploy
2013年5月2日 上午11:11
答复

Konstantin Chudinov

等级: Junior Member

帖子: 43

加入日期: 2013年4月23日

最近的帖子

I have the same issue! But in my case, everything is not so simpleemoticon
I also used this awrful blog:
http://www.liferay.com/about-us/privacy/-/blogs/6831821/maximized
It's stale!
Don't use it!
In my case liferay don't see
<property name="mappingResources">
<list>
<value>META-INF/portlet-hbm.xml</value>
</list>
</property>

I deleted these strings and I cought error with hibernate sql. i dont inderstand the reason, and I don't want to! I have small time to solve this problem and I spent the whole day for it.

DO SOMEBODY HAS COMPLETE WORKING EXAMPLE FOR LIFERAY 6.1 for connecting to external DB???
Francis Franco Freich
RE: Service Builder With Custom DataSource Breaks Hot Deploy
2013年5月3日 上午12:58
答复

Francis Franco Freich

等级: New Member

帖子: 10

加入日期: 2011年5月16日

最近的帖子

Konstantin Chudinov:
I have the same issue! But in my case, everything is not so simpleemoticon
I also used this awrful blog:
http://www.liferay.com/about-us/privacy/-/blogs/6831821/maximized
It's stale!
Don't use it!
In my case liferay don't see
<property name="mappingResources">
<list>
<value>META-INF/portlet-hbm.xml</value>
</list>
</property>

I deleted these strings and I cought error with hibernate sql. i dont inderstand the reason, and I don't want to! I have small time to solve this problem and I spent the whole day for it.

DO SOMEBODY HAS COMPLETE WORKING EXAMPLE FOR LIFERAY 6.1 for connecting to external DB???


Are you tied to particular technologies? Other than Liferay of course.
Harry Mark
RE: Service Builder With Custom DataSource Breaks Hot Deploy
2013年5月5日 下午5:14
答复

Harry Mark

等级: New Member

帖子: 1

加入日期: 2010年10月6日

最近的帖子

To get it working I searched hibernate-spring.xml (in Liferay source) for bean definitions that reference "liferayDataSource". Copied the definitions and renamed them, changing some of the properties for the portlet. Note: jdbc/ExternalPool is a global Tomcat data source.

Here's the ext-spring.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="externalDataSource" class="com.liferay.portal.spring.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName">
<value>jdbc/ExternalPool</value>
</property>
</bean>

<bean id="externalHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortalHibernateConfiguration">
<property name="dataSource" ref="externalDataSource" />
<property name="mappingResources">
<list>
<value>/META-INF/portlet-hbm.xml</value>
</list>
</property>
</bean>

<bean id="externalSessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl">
<property name="sessionFactoryClassLoader" ref="portletClassLoader" />
<property name="sessionFactoryImplementor" ref="externalHibernateSessionFactory" />
</bean>

<bean id="externalTransactionManager" class="com.liferay.portal.spring.transaction.TransactionManagerFactory" factory-method="createTransactionManager">
<constructor-arg ref="externalDataSource" />
<constructor-arg ref="externalHibernateSessionFactory" />
</bean>
</beans>


To use the external data source in service.xml objects, you need to set the data-source, session-factory & tx-manager attributes to these bean IDs. Run the "build-service" target then "deploy":

<entity name="Student" local-service="true" remote-service="false" data-source="externalDataSource" session-factory="externalSessionFactory" tx-manager="externalTransactionManager">
....


Note that the corresponding database objects must already exist in the external DB.