Fórumok

Liferay 6.0.6 Problem with hibernate insert in to database

Mitko Zafirovski, módosítva 11 év-val korábban

Liferay 6.0.6 Problem with hibernate insert in to database

Junior Member Bejegyzések: 26 Csatlakozás dátuma: 2012.03.01. Legújabb bejegyzések
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):

 <entity name="Entity" uuid="true" local-service="true" remote-service="false" cache-enabled="false">

        <!-- PK fields -->
        <column name="entityId" type="long" primary="true" />

        <!-- Other Fields -->
        <column name="entityName" type="String"></column>
        <column name="visible" type="boolean"></column>
    </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:

public Enitity createNewEntity(String name, boolean visible)throws SystemException{
Entity entity = entityPesistence.create(counterLocalService.increment(Entity.class.name()));
//Some bussiness logic here 
return entityPesistence.update(entity,false);
}


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.
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: Liferay 6.0.6 Problem with hibernate insert in to database

Liferay Legend Bejegyzések: 14914 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Liferay 6.0.6 Problem with hibernate insert in to database

Junior Member Bejegyzések: 26 Csatlakozás dátuma: 2012.03.01. Legújabb bejegyzések
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
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: Liferay 6.0.6 Problem with hibernate insert in to database

Liferay Legend Bejegyzések: 14914 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Liferay 6.0.6 Problem with hibernate insert in to database

Junior Member Bejegyzések: 26 Csatlakozás dátuma: 2012.03.01. Legújabb bejegyzések
Thanks for the info David, i tried that earlier this morning and it worked for me.
thumbnail
jelmer kuperus, módosítva 11 év-val korábban

RE: Liferay 6.0.6 Problem with hibernate insert in to database

Liferay Legend Bejegyzések: 1191 Csatlakozás dátuma: 2010.03.10. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Liferay 6.0.6 Problem with hibernate insert in to database

Junior Member Bejegyzések: 26 Csatlakozás dátuma: 2012.03.01. Legújabb bejegyzések
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.