|
[
Permalink
| « Hide
]
Steve Ebersole added a comment - 10/May/07 07:33 AM
Need a test case. Are you using a custom dialect?
hibernate.dialect org.hibernate.dialect.MySQL5InnoDBDialect
Nothing other change except hibernate3.jar from version 3.2.3 to version 3.2.4 Currently I rollback to old version 3.2.3 and all working fine again. I think, that INSERT SQL query must be without row id column, because it is autoincrement. Hibernate 3.2.4 INSERT SQL: insert into PaymentDO (_version, comment, created, customer_id, nalichka, newBalance, payDate, sum, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?) Must be: insert into PaymentDO (_version, comment, created, customer_id, nalichka, newBalance, payDate, sum) values (?, ?, ?, ?, ?, ?, ?, ?) Sure, and that is based on dialect. The mysql dialects have not changed between 3.2.3 and 3.2.4. Hence why I need a test case
I have not test case, but I can show same trace log of 3.2.3 version:
10.05.07 18:03:40 DEBUG [btpool0-0]: SQL - insert into PaymentDO (_version, comment, created, customer_id, nalichka, newBalance, payDate, sum) values (?, ?, ?, ?, ?, ?, ?, ?) 10.05.07 18:03:40 TRACE [btpool0-0]: AbstractBatcher - preparing statement 10.05.07 18:03:40 TRACE [btpool0-0]: AbstractEntityPersister - Dehydrating entity: [org.dicr.isp.data.PaymentDO#<null>] 10.05.07 18:03:40 TRACE [btpool0-0]: LongType - binding '0' to parameter: 1 10.05.07 18:03:40 TRACE [btpool0-0]: StringType - binding null to parameter: 2 10.05.07 18:03:40 TRACE [btpool0-0]: TimestampType - binding '2007-05-10 18:03:40' to parameter: 3 10.05.07 18:03:40 TRACE [btpool0-0]: VersionValue - version unsaved-value strategy UNDEFINED 10.05.07 18:03:40 TRACE [btpool0-0]: IdentifierValue - id unsaved-value: 0 10.05.07 18:03:40 TRACE [btpool0-0]: LongType - binding '18128' to parameter: 4 10.05.07 18:03:40 TRACE [btpool0-0]: BooleanType - binding 'false' to parameter: 5 10.05.07 18:03:40 TRACE [btpool0-0]: FloatType - binding '6.0' to parameter: 6 10.05.07 18:03:40 TRACE [btpool0-0]: TimestampType - binding '2007-05-10 00:00:00' to parameter: 7 10.05.07 18:03:40 TRACE [btpool0-0]: FloatType - binding '3.0' to parameter: 8 10.05.07 18:03:40 DEBUG [btpool0-0]: IdentifierGeneratorFactory - Natively generated identity: 151549 10.05.07 18:03:40 DEBUG [btpool0-0]: AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1) 10.05.07 18:03:40 TRACE [btpool0-0]: AbstractBatcher - closing statement 10.05.07 18:03:40 DEBUG [btpool0-0]: JDBCTransaction - commit I've the same problem with SQLServer.
It seems to be a bug in org.hibernate.persister.entity.AbstractEntityPersister. When generateInsertString() is called, the line #1900 in AbstractEntityPersister.java add the ID column which should be an auto-generated column as a normal column. I presume you are talking about this code:
// add the primary key if ( j == 0 && identityInsert ) { insert.addIdentityColumn( getKeyColumns( 0 )[0] ); } else { insert.addColumns( getKeyColumns( j ) ); } ? Well for the base tablle (j==0) of entities with an identity PK (identityInsert==true) we call the special Insert#addIdentityColumn method. That method *conditionally* add the identity column to the insert based on what the dialect says... So, yes, I need a test case. Running the unit test using MySQLInnoDBDialect found 6 failures and 205 errors. There were 200 occurrences of the string "No value specified for parameter".
There were 6 failures and 5 errors when running Hypersonic with 0 occurrences of the string. I believe this bug was introduced by the fix for After changing: sqlIdentityInsertString = sqlInsertStrings[0] == null ? generateIdentityInsertString( getPropertyInsertability() ) : sqlInsertStrings[0]; to: sqlIdentityInsertString = customSQLInsert[0] == null ? generateIdentityInsertString( getPropertyInsertability() ) : customSQLInsert[0]; (as suggested by Scott Rankin in I'm having the same problem with MySQL 5 and org.hibernate.dialect.MySQLDialect. All our IDs are auto-increment, and we are using generator=native.
This is readily apparent when attempting to save any entity. I'm seeing this with MySQL5 and org.hibernate.dialect.MySQL5Dialect
I have the same issue, my app. was working fine with 3.2.2 and 3.2.3 but fails with 3.2.4. Notice that in my case I use Informix dialect.
See below the difference of the SQL (captured with the p6spy jdbc driver). In my case the field ID is an Informix serial field which gets auto-incremented by Informix: 3.2.3: 2007-05-14 14:53:08,434|16|2|statement|insert into ACSLOG (VERNO_CTX, ACSDATE, ACSTIME, ACSUSR, DESCR) values (?, ?, ?, ?, ?)|insert into ACSLOG (VERNO_CTX, ACSDATE, ACSTIME, ACSUSR, DESCR) values (0, '2007-05-14', 145307, 'testuser', 'test') 3.2.4: 2007-05-14 14:55:35,018|31|2|statement|insert into ACSLOG (VERNO_CTX, ACSDATE, ACSTIME, ACSUSR, DESCR, ID) values (?, ?, ?, ?, ?, ?)|insert into ACSLOG (VERNO_CTX, ACSDATE, ACSTIME, ACSUSR, DESCR, ID) values (0, '2007-05-14', 145532, 'testuser', test, null) See the corresponding bit of mapping below: <id name="id" column="ID" access="field"> <generator class="native" /> </id> So, 3.2.4 is adding the ID column to the insert statement when it should not, on top of that it is setting its value to null, which conflicts with my table definition (as this is the PK). Same problem as Igor. I've the same problem as above, with this exception when I try to 'persist' an entity bean like the following one in a mysql database (version 5.0.38) :
package quickstart.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity public class Person { @Id @GeneratedValue private Integer id; private String lastName; private String firstName; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } } I use spring 2.0 and xwork 2.0.1. The save method is : public void save(Person person) { if (person.getId() == null) { // new log.debug("public void save(Person person) : before em.persist(person);"); em.persist(person); log.debug("public void save(Person person) : after em.persist(person);"); } else { // update em.merge(person); } } I get this error : 15:39:49,381 INFO [STDOUT] Hibernate: insert into Person (firstName, lastName, id) values (?, ?, ?) 15:39:49,478 INFO [STDOUT] 15:39:49,477 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 07001 15:39:49,478 INFO [STDOUT] 15:39:49,478 ERROR [JDBCExceptionReporter] No value specified for parameter 3 15:39:49,490 INFO [STDOUT] 15:39:49,486 ERROR [[default]] Servlet.service() for servlet default threw exception javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [quickstart.model.Person] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630) at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:237) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:180) at $Proxy87.merge(Unknown Source) at quickstart.service.PersonServiceImpl.save(PersonServiceImpl.java:46) I tried to manually insert via phpmyadmin the same row in the database, and notice that if the 'id' is not set (as it's setted to 'auto increment' in the table), the generated query is : INSERT INTO `Person` ( `id` , `firstName` , `lastName` ) VALUES ( NULL , 'first1', 'last1' ); thus, the 'id' column is well setted but to a NULL value, and it's works, the row is added. This hibernate bug is blocking for me. For what it's worth, we're seeing the same behavior in only 3.2.4 with our objects which use autogenerated keys (e.g., including the 'id' field in the insert statement). AS400Dialect.
Similar problem here with DB2 and any mappings that use a "native" generator. Looking at the debug logs, I see that the "identity insert" string has changed between 3.2.3 and 3.2.4. Here's an example:
3.2.3: insert into USER_BOOKMARK_GROUP (USER_BOOKMARK_GROUP_ID, UPDATE_TIMESTAMP, CREATE_TIMESTAMP, CREATE_USER, UPDATE_USER, INACTIVE_DATE, USER_ID, GROUP_NAME, SEQUENCE_NUMBER) values (default, ?, ?, ?, ?, ?, ?, ?, ?) 3.2.4: insert into USER_BOOKMARK_GROUP (UPDATE_TIMESTAMP, CREATE_TIMESTAMP, CREATE_USER, UPDATE_USER, INACTIVE_DATE, USER_ID, GROUP_NAME, SEQUENCE_NUMBER, USER_BOOKMARK_GROUP_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?) The latter causes DB2 to throw an exception in 3.2.4. Prior versions (including 3.2.3) worked fine. Yes, actually this has been verified to be a serious bug. Unfortunately I have been traveling the past few days and have not had a chance to fix it as of yet. However, I just returned home and will have a patch release out tomorrow fixing the issue.
FYI, the same code as I pasted above works well (no exceptions when call EntityManager.persist with ID primary key setted to @GeneratedValue) with the last version 3.2.3 of hibernate. Notice : I've only changed the hibernate librairies core from 3.2.4 to 3.2.3, but I still work with hibernate-annotations-3.3.0.GA and hibernate-entitymanager-3.3.1.GA.
Could you please update dependencies of hibernate-entitymanager pom.xml in Maven repositories? The current version 3.3.1.GA still refers the buggy version 3.2.4 of hibernate core.
Regards, Ollie The POM issue has still not been fixed, i'm seeing
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>3.2.4.ga</version> </dependency> in the file hibernate-entitymanager-3.3.1.ga.pom . Oliver do you know what the workaround for this is? Do I just manually edit my pom in my local repository? To answer my own question my problem was that i didn't have an explicit dependency on hibernate core, ie I was missing the first dependency listed below, which meant that hibernate core 3.2.4 was being included because it is a dependency of hibernate-entitymanager 3.3.1
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>3.2.6.ga</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>3.3.1.ga</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-tools</artifactId> <version>3.2.0.ga</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>3.3.0.ga</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>3.3.1.ga</version> </dependency> No Oliver we cannot.
1) Those are not poms developed by the Hibernate team 2) You *never* update released poms in repositories; this is why Maven repos get screwed up The correct solution would be for your project to define a dep to 3.2.6 in <dependencyManagement/> |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||