Issue Details (XML | Word | Printable)

Key: HHH-2605
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Steve Ebersole
Reporter: Igor A Tarasov
Votes: 18
Watchers: 22
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

Since 3.2.4 no value specified for row id

Created: 10/May/07 07:12 AM   Updated: Thursday 11:09 AM
Component/s: core
Affects Version/s: 3.2.4
Fix Version/s: 3.2.4.sp1

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive noid.zip (1 kB)
2. Zip Archive noidTestCase.zip (1 kB)

Environment:
hibernate-3.2.4
mysql-5.0.27-1.fc6
mysql-connector-java-5.0.5-bin.jar
Issue Links:
Duplicate
 


 Description  « Hide
Problem starts in 3.2.4 version, but in 3.2.3 was all right.
Row ID column is specified as parameter in query, but no value is specified.
Row ID column is autoincrement in MySQL tabled.

10.05.07 14:26:29 DEBUG [btpool0-0]: SQL - insert into PaymentDO (_version, comment, created, customer_id, nalichka, newBalance, payDate, sum, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
10.05.07 14:26:29 TRACE [btpool0-0]: AbstractBatcher - preparing statement
10.05.07 14:26:29 TRACE [btpool0-0]: AbstractEntityPersister - Dehydrating entity: [org.dicr.isp.data.PaymentDO#<null>]
10.05.07 14:26:29 TRACE [btpool0-0]: LongType - binding '0' to parameter: 1
10.05.07 14:26:29 TRACE [btpool0-0]: StringType - binding null to parameter: 2
10.05.07 14:26:29 TRACE [btpool0-0]: TimestampType - binding '2007-05-10 14:26:29' to parameter: 3
10.05.07 14:26:29 TRACE [btpool0-0]: VersionValue - version unsaved-value strategy UNDEFINED
10.05.07 14:26:29 TRACE [btpool0-0]: IdentifierValue - id unsaved-value: 0
10.05.07 14:26:29 TRACE [btpool0-0]: LongType - binding '18128' to parameter: 4
10.05.07 14:26:29 TRACE [btpool0-0]: BooleanType - binding 'false' to parameter: 5
10.05.07 14:26:29 TRACE [btpool0-0]: FloatType - binding '3.0' to parameter: 6
10.05.07 14:26:29 TRACE [btpool0-0]: TimestampType - binding '2007-05-10 00:00:00' to parameter: 7
10.05.07 14:26:29 TRACE [btpool0-0]: FloatType - binding '3.0' to parameter: 8
10.05.07 14:26:29 DEBUG [btpool0-0]: AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
10.05.07 14:26:29 TRACE [btpool0-0]: AbstractBatcher - closing statement
10.05.07 14:26:29 DEBUG [btpool0-0]: JDBCExceptionReporter - could not insert: [org.dicr.isp.data.PaymentDO] [insert into PaymentDO (_version, comment, created, customer_id, nalichka, newBalance, payDate, sum, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)]
java.sql.SQLException: No value specified for parameter 9
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1674)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1512)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1455)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1440)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:213)
at org.dicr.isp.data.HibernateDataManager.createPayment(HibernateDataManager.java:692)


 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Steve Ebersole added a comment - 10/May/07 07:33 AM
Need a test case. Are you using a custom dialect?

Igor A Tarasov added a comment - 10/May/07 08:42 AM
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 (?, ?, ?, ?, ?, ?, ?, ?)

Steve Ebersole added a comment - 10/May/07 09:41 AM
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

Igor A Tarasov added a comment - 10/May/07 10:04 AM
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

wesley wu added a comment - 10/May/07 05:50 PM
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.

wesley wu added a comment - 10/May/07 05:52 PM
It takes me nearly 10 hours to figure it out. :(
I may provide a test case, but too busy to do so today.

Steve Ebersole added a comment - 10/May/07 08:44 PM
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.

Gail Badner added a comment - 11/May/07 03:41 PM
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 HHH-2301.

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 HHH-2301), the results from using MySQLInnoDBDialect gave 6 failures and 7 errors. I'm looking into whether any of these are unexpected.

Manuel Dominguez Sarmiento added a comment - 13/May/07 06:40 PM
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.

Donnchadh O Donnabhain added a comment - 14/May/07 11:32 AM
I'm seeing this with MySQL5 and org.hibernate.dialect.MySQL5Dialect

Donnchadh O Donnabhain added a comment - 14/May/07 12:15 PM
Fixed typo

Todd Huss added a comment - 14/May/07 06:16 PM
Same issue here, after upgrading from 3.2.2 to 3.2.4 all of my unit tests are failing with this issue.

Juan F Cervera added a comment - 15/May/07 04:38 AM
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.





franck evrard added a comment - 15/May/07 09:20 AM
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.
 

Ron Eisele added a comment - 15/May/07 12:19 PM
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.

Reggie Riser added a comment - 15/May/07 02:05 PM
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.

Steve Ebersole added a comment - 15/May/07 10:14 PM
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.

franck evrard added a comment - 16/May/07 04:06 AM
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.

Steve Ebersole added a comment - 18/May/07 07:38 AM
prep 3.2.4.sp1

Oliver Gierke added a comment - 31/Jan/08 06:16 AM
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

Murray Waters added a comment - 06/Jun/08 12:56 AM
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?

Murray Waters added a comment - 06/Jun/08 01:03 AM
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>

Steve Ebersole added a comment - 06/Jun/08 09:12 AM
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/>