[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2605?page=c...
]
evrard commented on HHH-2605:
-----------------------------
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.
Since 3.2.4 no value specified for row id
-----------------------------------------
Key: HHH-2605
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2605
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.4
Environment: hibernate-3.2.4
mysql-5.0.27-1.fc6
mysql-connector-java-5.0.5-bin.jar
Reporter: Igor A Tarasov
Attachments: noid.zip, noidTestCase.zip
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)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira