[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5429) [regression] unable to persist entity using derby 10.6.1.0 and hibernate 3.5+

Fabien Marsaud (JIRA) noreply at atlassian.com
Tue Feb 21 21:28:10 EST 2012


    [ https://hibernate.onjira.com/browse/HHH-5429?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45577#comment-45577 ] 

Fabien Marsaud commented on HHH-5429:
-------------------------------------

I believe this issue can be closed: Hibernate now simply abides by http://db.apache.org/derby/docs/10.6/ref/rrefsqlj37836.html ID generation.

Let's assume your entities are declared with:
  @javax.persistence.Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Long getId() { return id; }

At the time of Hibernate 3.3, if your DB was created using the output of configuration.generateSchemaCreationScript(new DerbyDialect()), you must have got some HIBERNATE_UNIQUE_KEY table which acted as a sequence for Hibernate to fill entities' IDs before INSERT. With Hibernate 3.5+ the DDL statements would contain "generated by default as identity" next to each PK declaration.

In other words, now, Hibernate has a good reason *not* to fill the ID of entities to be inserted: it considers Derby should manage them instead. If you want to keep your Derby IDs as they *were* (without generated identity), just fill the ID column yourself before INSERT. We could have the same with not autoincremented MySQL tables PKs.

To fix, you may want to export data, drop contraints+tables, regenerate creation script, check it contains "generated always/by default as identity", create tables, re-insert data, restore constraints, enjoy.

> [regression] unable to persist entity using derby 10.6.1.0 and hibernate 3.5+
> -----------------------------------------------------------------------------
>
>                 Key: HHH-5429
>                 URL: https://hibernate.onjira.com/browse/HHH-5429
>             Project: Hibernate ORM
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.5.3, 3.5.4, 3.6.0.Beta1
>         Environment: derby 10.6.1.0 and hibernate 3.5+
>            Reporter: Max Giesbert
>
> when inserting any kind of entity
> @Entity
> public class TestObject
> {
> 	private Long id;
> 	
> 	private String test;
> 	
> 	public TestObject(){}
> 	
> 	@Id @GeneratedValue(strategy=GenerationType.AUTO)
> 	public Long getId()
> 	{
> 		return id;
> 	}
> [...]
> i get the following error message
> org.hibernate.exception.ConstraintViolationException: could not insert: [com.mypackage.TestObject]
> >>java.sql.SQLIntegrityConstraintViolationException: Column 'ID'  cannot accept a NULL value.
> >>org.apache.derby.impl.jdbc.EmbedSQLException: Column 'ID'  cannot accept a NULL value.
> >>ERROR 23502: Column 'ID'  cannot accept a NULL value.
> >>	at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
> >>	at org.apache.derby.impl.sql.execute.NormalizeResultSet.normalizeColumn(Unknown Source)
> >>	at org.apache.derby.impl.sql.execute.NormalizeResultSet.normalizeRow(Unknown Source)
> >>	at org.apache.derby.impl.sql.execute.NormalizeResultSet.getNextRowCore(Unknown Source)
> >>	at org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(Unknown Source)
> >>...
> the same code is working fine with versions 3.3.2GA and annotations 3.4.0GA and earlier. i just switched back...

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list