[
https://hibernate.onjira.com/browse/HHH-6648?page=com.atlassian.jira.plug...
]
Brad Maxwell commented on HHH-6648:
-----------------------------------
Sorry I missed the message, I'm looking at AS 7 again and will retest. This was a
simple app developed with hibernate 3 using @GenereatedValue which was setting auto
increment. I recompiled the app against the AS 7.1 Alpha and started it against a new
database where the tables had not been created and at runtime when the app tried to
persist an object it failed because the auto increment had not been set.
@GeneratedValue not setting up auto increment in mysql and h2
dialects
----------------------------------------------------------------------
Key: HHH-6648
URL:
https://hibernate.onjira.com/browse/HHH-6648
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 4.0.0.Beta5
Environment: AS 7.0.1
Reporter: Brad Maxwell
Assignee: Steve Ebersole
Attachments: h2.txt, mysql.txt, testcase-HHH-6648.zip
I took this application that uses hibernate and moved it to AS 7.0.1. I found that when
using the H2 database, it fails complaining that the id is null. I tried changing it to
use the HSQL dialect and had the same issue. Then I changed the datasource and dialect to
MySQL and I got the same error. I'm attaching the full stack traces for mysql and
h2.
I then switched to Oracle ds / dialect and it worked fine.
I examined the database tables and found that it was not set to auto increment. So I
manually modified the database tables and that allowed the hibernate calls to succeed.
@Entity()
@Table()
public class EAPVersion implements Serializable
{
@Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id")
private int id;
@Column(name="name")
private String name;
@OneToMany(cascade=CascadeType.ALL) //, mappedBy="id")
@JoinColumn(name="EAPVersion_ID")
private List<Component> components = new ArrayList<Component>();
...
}
...
Caused by: javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: Field 'id' doesn't have a
default value
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1344)
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1277)
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1283)
at
org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:851)
at com.jboss.support.Cache.getEAPVersions(Cache.java:131)
at com.jboss.support.SourceCodeBean.getEapVersionsItems(SourceCodeBean.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
at org.apache.el.parser.AstValue.getValue(AstValue.java:134)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
... 36 more
Caused by: org.hibernate.exception.GenericJDBCException: Field 'id' doesn't
have a default value
at
org.hibernate.exception.internal.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:148)
at
org.hibernate.exception.internal.SQLStateConverter.convert(SQLStateConverter.java:136)
at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)
at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at
org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:131)
at
org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:80)
at $Proxy22.executeUpdate(Unknown Source)
at
org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:95)
at
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:54)
at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2753)
at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3259)
at
org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:78)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:273)
at
org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:301)
at
org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
at
org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:127)
at
org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78)
at
org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:178)
at
org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:134)
at
org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:64)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:718)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:694)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:698)
at
org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:845)
... 48 more
Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2415)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2333)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2318)
at
org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at
org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:124)
... 67 more
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira