Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Mitko Zafirovski
Liferay 6.0.6 Problem with hibernate insert in to database
January 25, 2013 7:39 AM
Answer

Mitko Zafirovski

Rank: Junior Member

Posts: 27

Join Date: March 1, 2012

Recent Posts

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
January 25, 2013 9:45 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7064

Join Date: September 1, 2006

Recent Posts

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
January 28, 2013 1:36 AM
Answer

Mitko Zafirovski

Rank: Junior Member

Posts: 27

Join Date: March 1, 2012

Recent Posts

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
January 28, 2013 5:37 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7064

Join Date: September 1, 2006

Recent Posts

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
January 28, 2013 12:09 PM
Answer

Mitko Zafirovski

Rank: Junior Member

Posts: 27

Join Date: March 1, 2012

Recent Posts

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
January 29, 2013 12:51 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

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
January 29, 2013 12:47 AM
Answer

Mitko Zafirovski

Rank: Junior Member

Posts: 27

Join Date: March 1, 2012

Recent Posts

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.