论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Mitko Zafirovski
Liferay 6.0.6 Problem with hibernate insert in to database
2013年1月25日 上午7:39
答复

Mitko Zafirovski

等级: Junior Member

帖子: 27

加入日期: 2012年3月1日

最近的帖子

Hello all. I have a Liferay 6.0.6 behind a Glassfish connected to a DB2 9.7.
We've been using the service builder very often and never had a problem with it. Some time ago some weird problems started to appear when some of the data was not found in the database.
I will post some snapshot to explain what is our approach to storing in the db:
First of all all our entities look as the following (will use proxy's as i am not allowed to share the code):
 1
 2 <entity name="Entity" uuid="true" local-service="true"
 3            remote-service="false" cache-enabled="false">
 4
 5        <!-- PK fields -->
 6        <column name="entityId" type="long" primary="true" />
 7
 8        <!-- Other Fields -->
 9        <column name="entityName" type="String"></column>
10        <column name="visible" type="boolean"></column>
11    </entity>

Now the entity in question has many more columns though i dont think that is causing the problems.
Furthermore once the service-builder runs and all Services are created we have some business logic. A sample is something like:
1
2public Enitity createNewEntity(String name, boolean visible)throws SystemException{
3Entity entity = entityPesistence.create(counterLocalService.increment(Entity.class.name()));
4//Some bussiness logic here
5return entityPesistence.update(entity,false);
6}


The problem like i mentioned above that started couple of months ago is that once calling this method through the Util class it returns a Entity object with Id and everything but its not persisted through the database. The even weirder thing is that after several attempts with the same data it will finally be persisted. I switched on the hibernate.show_sql=true property to see what its beeing persisted and i cannot find an insert in to the DB. There is no error or warrning or anything, it act as the insert has been executed but its actually not. This problem only occurs on one entity only though all the settings are the same whit everything else we use.

If anyone has any ideas what might be the problem please share them with me.
Thanks for the help.
David H Nebinger
RE: Liferay 6.0.6 Problem with hibernate insert in to database
2013年1月25日 上午9:45
答复

David H Nebinger

等级: Liferay Legend

帖子: 7895

加入日期: 2006年9月1日

最近的帖子

Well, my first suggestion is that you should not be calling out to the persistence layer unless absolutely necessary, especially since Liferay may change how the superclass handles the creation/update. The super class will have a createEntity() method and an updateEntity() method that you should use instead.

Not that I think it's you're problem here, but it is best to follow appropriate procedure to guarantee future compatibility.

That said, have you checked to see whether you're getting and/or discarding an exception within your createNewEntity() method?

I.e. do a try/catch block within createNewEntity() to intercept any exceptions going on?
Mitko Zafirovski
RE: Liferay 6.0.6 Problem with hibernate insert in to database
2013年1月28日 上午1:36
答复

Mitko Zafirovski

等级: Junior Member

帖子: 27

加入日期: 2012年3月1日

最近的帖子

Hello David thanks for the response.
I see your point on going from the super class not the persistence, though i followed the examples presented this post that shows creating a new entity by using the persistence. Anyways i can understand the problems you were mentioning and i will try to follow the super class example. However that did not solve my problem. I just traced the problem to the hibernate.jdbc.batch_size and it flushes the session after X amount of calls. This is my problem because i'm using a DynamicQuery right after i try to update the entity. I was think of setting the batch_size to 0 because i know that will solve this problem but i'm a bit skeptical since that might cause other problems also. Do u have any suggestions on this?
Thanks
David H Nebinger
RE: Liferay 6.0.6 Problem with hibernate insert in to database
2013年1月28日 上午5:37
答复

David H Nebinger

等级: Liferay Legend

帖子: 7895

加入日期: 2006年9月1日

最近的帖子

I think it's okay to set your batch size to 0, and even though it may have a performance impact (by flushing all changes to disk rather than queuing them up) it sounds like it's something you need to do.

Use portal-ext.properties to set hibernate.jdbc.batch_size=0 to accomplish this.
Mitko Zafirovski
RE: Liferay 6.0.6 Problem with hibernate insert in to database
2013年1月28日 下午12:09
答复

Mitko Zafirovski

等级: Junior Member

帖子: 27

加入日期: 2012年3月1日

最近的帖子

Thanks for the info David, i tried that earlier this morning and it worked for me.
Jelmer Kuperus
RE: Liferay 6.0.6 Problem with hibernate insert in to database
2013年1月29日 上午12:51
答复

Jelmer Kuperus

等级: Liferay Legend

帖子: 1192

加入日期: 2010年3月10日

最近的帖子

That seems strange, Querying for something that has not been saved should cause a flush of the session in hibernate. Are you sure you are using the same session ? or did you fiddle with the flushmode ?
Mitko Zafirovski
RE: Liferay 6.0.6 Problem with hibernate insert in to database
2013年1月29日 上午12:47
答复

Mitko Zafirovski

等级: Junior Member

帖子: 27

加入日期: 2012年3月1日

最近的帖子

I am 100% sure i'm using the same sessions and no i haven't changed anything. It also struck me as strange since i have similar scenarios on different services and i didn't encounter this problem before.