[hibernate-dev] 'INSERT' transactions are always rolled back on PostgreSQL when partitioning is used.
Hi All, I have created a simple java application running on glassfish and using a hibernate as a persistence provider on PostgreSQL. I just simply insert display and delete rows from a table. Everything worked fine but when I use partitioning on tables as described at http://www.postgresql.org/docs/8.2/static/ddl-partitioning.html The application started to report every insert to the table as "Transaction marked for rollback" and throwing an exception javax.persistence.OptimisticLockException: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 at org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:654) at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:600) at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:525) (plenty of more lines) Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61) at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46) at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338) at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:516) ... 50 more This is due that Statement.executeBatch returns the incorrect number of rows affected by the transaction. This number returned by PostgreSQL is defined at http://www.postgresql.org/docs/8.2/static/rules-status.html Since the rule system in general is too complex in PostgreSQL it is not possible to define the command status string so it would contain the number of rows affected by the transaction. I think that JDBC driver should return Statement.SUCCESS_NO_INFO in this case, however, it is not doing so now and the JDBC spec does not allow to return Statement.SUCCESS_NO_INFO in Statement.executeUpdate. I had a look at hibernate source where there are couple of "Expectations" implementations but I have not found how it is possible to choose different implementation in my application. A workaround for this could be that I can use Expectation.NONE as an "Expectations" instance. Is it possible to set this up in an application code/configuration? I have not found anything like this in documentation. Thanks for your comments. Cheers Julo ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev
[hibernate-dev] ResultCheckStyle.PARAM does not work with PostgreSQL
Hi All, I have created a simple test application which uses a stored procedure to insert a record into a database using hibernate. I used hibernate annotations and have overridden insert statement by @SQLInsert(callable=true, sql="{? = call insert_party(?, ?, ?, ?)}", check=ResultCheckStyle.PARAM) However, hibernate throws the exception ... Caused by: org.hibernate.exception.GenericJDBCException: could not extract row counts from CallableStatement at org.hibernate.jdbc.Expectations$BasicParamExpectation.determineRowCount(Expectations.java:123) at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:41) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2251) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2661) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338) at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:516) ... 50 more Caused by: org.postgresql.util.PSQLException: Parameter of type java.sql.Types=2 was registered, but call to getInt (sqltype=java.sql.Types=4) was made. at org.postgresql.jdbc2.AbstractJdbc2Statement.checkIndex(AbstractJdbc2Statement.java:2387) at org.postgresql.jdbc2.AbstractJdbc2Statement.getInt(AbstractJdbc2Statement.java:1920) at org.hibernate.jdbc.Expectations$BasicParamExpectation.determineRowCount(Expectations.java:119) ... 62 more I studied JDBC3 specification whether PostgreSQL driver is wrong or not and I think that the driver is correct. There is a conversion table on page B-182 which should correspond to ResultSet object getter methods only. There is nothing about the conversion being done in CallableStatement's getter methods. Attached is the patch agains hibernate core Branch_3_2 which fixes the issue using getBigDecimal(parameterPosition).intValue() Please, could someone review the fix and apply the patch? Could you also back port the fix? Thank you. Regards Julius Stroffek Index: src/org/hibernate/jdbc/Expectations.java === --- src/org/hibernate/jdbc/Expectations.java (revision 14203) +++ src/org/hibernate/jdbc/Expectations.java (working copy) @@ -8,6 +8,7 @@ import org.hibernate.util.JDBCExceptionReporter; import org.hibernate.exception.GenericJDBCException; +import java.math.BigDecimal; import java.sql.CallableStatement; import java.sql.SQLException; import java.sql.PreparedStatement; @@ -116,7 +117,7 @@ protected int determineRowCount(int reportedRowCount, PreparedStatement statement) { try { -return toCallableStatement( statement ).getInt( parameterPosition ); +return toCallableStatement( statement ).getBigDecimal( parameterPosition ).intValue(); } catch( SQLException sqle ) { JDBCExceptionReporter.logExceptions( sqle, "could not extract row counts from CallableStatement" ); ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev
Re: [hibernate-dev] ResultCheckStyle.PARAM does not work with PostgreSQL
Sorry, I sent this mail only to Max, so resending it to the list. Please, review the patch. Thanks. Max Rydahl Andersen wrote: patches should go to the jira. Thanks Max, I have created an issue *HHH-2962 <http://opensource.atlassian.com/projects/hibernate/browse/HHH-2962> *in jira and I have attached a patch. Should I somehow mark that there is a patch pending for review? what do you mean by backport ? I meant porting to 3.2 branch. Usually, patches are applied against head by default in projects I am familiar with. I am not quite sure how things work for hibernate. Thanks Cheers Julo /max Hi All, I have created a simple test application which uses a stored procedure to insert a record into a database using hibernate. I used hibernate annotations and have overridden insert statement by @SQLInsert(callable=true, sql="{? = call insert_party(?, ?, ?, ?)}", check=ResultCheckStyle.PARAM) However, hibernate throws the exception ... Caused by: org.hibernate.exception.GenericJDBCException: could not extract row counts from CallableStatement at org.hibernate.jdbc.Expectations$BasicParamExpectation.determineRowCount(Expectations.java:123) at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:41) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2251) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2661) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338) at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:516) ... 50 more Caused by: org.postgresql.util.PSQLException: Parameter of type java.sql.Types=2 was registered, but call to getInt (sqltype=java.sql.Types=4) was made. at org.postgresql.jdbc2.AbstractJdbc2Statement.checkIndex(AbstractJdbc2Statement.java:2387) at org.postgresql.jdbc2.AbstractJdbc2Statement.getInt(AbstractJdbc2Statement.java:1920) at org.hibernate.jdbc.Expectations$BasicParamExpectation.determineRowCount(Expectations.java:119) ... 62 more I studied JDBC3 specification whether PostgreSQL driver is wrong or not and I think that the driver is correct. There is a conversion table on page B-182 which should correspond to ResultSet object getter methods only. There is nothing about the conversion being done in CallableStatement's getter methods. Attached is the patch agains hibernate core Branch_3_2 which fixes the issue using getBigDecimal(parameterPosition).intValue() Please, could someone review the fix and apply the patch? Could you also back port the fix? Thank you. Regards Julius Stroffek ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev
[hibernate-dev] Running tests with different configurations and different databases
Hi All, Is there a document describing how to run hibernate junit tests with various configurations? I would like to run the tests against PostgreSQL but I am not able to find any description how to do that. I would like to implement a test for http://opensource.atlassian.com/projects/hibernate/browse/HHH-2962. Thanks a lot. Cheers Julo ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev
[hibernate-dev] please review HHH-2962
Hi All, I have attached a patch also with a test case for HHH-2962 and since I do not have enough rights in JIRA to change the issue status from 'Awaiting Test Case' to something that people would have a notice on it, I am posting a message to the list. Please review the patch and provide some comments. Thanks. Cheers Julo ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev
Re: [hibernate-dev] please review HHH-2962
Hi, could someone please review the patch for HHH-2962. It is pending there for a while and I think it is a simple patch and you should not spent much time on it. Thanks a lot. Cheers Julo Gail Badner wrote: Hi Julius, Thanks for the test case. I've indicated that the test case was received for the issue, so now the status is set to "Open". Gail Julius Stroffek wrote: Hi All, I have attached a patch also with a test case for HHH-2962 and since I do not have enough rights in JIRA to change the issue status from 'Awaiting Test Case' to something that people would have a notice on it, I am posting a message to the list. Please review the patch and provide some comments. Thanks. Cheers Julo ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev
Re: [hibernate-dev] please review HHH-2962
Hi, is there something I could do to get this fix reviewed? Thanks Julo Julius Stroffek wrote: Hi, could someone please review the patch for HHH-2962. It is pending there for a while and I think it is a simple patch and you should not spent much time on it. Thanks a lot. Cheers Julo Gail Badner wrote: Hi Julius, Thanks for the test case. I've indicated that the test case was received for the issue, so now the status is set to "Open". Gail Julius Stroffek wrote: Hi All, I have attached a patch also with a test case for HHH-2962 and since I do not have enough rights in JIRA to change the issue status from 'Awaiting Test Case' to something that people would have a notice on it, I am posting a message to the list. Please review the patch and provide some comments. Thanks. Cheers Julo ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev