-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: @Generated annotation issue
PostPosted: Wed Jun 20, 2007 6:55 pm 
Newbie

Joined: Fri Feb 16, 2007 3:18 pm
Posts: 6
Hibernate version:
Hibernate annotations version 3.2.0 GA

Mapping documents:
@Generated(GenerationTime.INSERT)
@Column (name="CreatedOn", length=23, nullable=false, insertable=false, updatable=false)
private Date mCreatedOn;

Full stack trace of any exception that occurs:
org.springframework.dao.DataIntegrityViolationException: could not insert: [classname]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [classname]
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [classname]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
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.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:635)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:632)
at classname
at classname
at classname
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 junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert the value NULL into column 'CreatedOn', table 'DB.dbo.Zone'; column does not allow nulls. INSERT fails.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getPrepExecResponse(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PreparedStatementExecutionRequest.executeStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
... 41 more



Name and version of the database you are using:
MSSQL 9.00.3042.00

The generated SQL (show_sql=true):
Hibernate: insert into Zone (CreatedByUserID, ZoneDescription, ZoneFile, ModifiedByUserID, ModifiedOn, ZoneName, RowStatus, SOAExpire, SOAMinimum, SOARefresh, SOARetry, SOAWho, ZoneTTL, ZoneType, ZoneClass) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Debug level Hibernate log excerpt:
18:37:42 WARN org.hibernate.util.JDBCExceptionReporter 77 SQL Error: 515, SQLState: 23000
18:37:42 ERROR org.hibernate.util.JDBCExceptionReporter 78 Cannot insert the value NULL into column 'CreatedOn', table 'DB.dbo.Zone'; column does not allow nulls. INSERT fails.

I did find the following bug submitted and stated as fixed in 3.20rc2, but when i tested against that new ejb and hibernate-annotations jar file, I still recieve the exception.

http://opensource.atlassian.com/project ... se/ANN-411

Am I doing something wrong with this Generated annotation? Im simply try to make sure that the DB handles the creation of this property.

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 8:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It's a bug, it has been fixed in a subsequent version.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 11:20 am 
Newbie

Joined: Fri Feb 16, 2007 3:18 pm
Posts: 6
Thanks for your reply.

What parts of hibernate was the fixed applied to, and what jars do I need to update?

hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate.jar
hibernate-tools.jar
ejb3-persistence.jar

Thanks again
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 3:16 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
hum are you using Hibernate Annotations 3.3.0 or 3.2.0?
Because the info you gave me are contradictory :)

Check the version nbr in the logs (INFO level)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 3:23 pm 
Newbie

Joined: Fri Feb 16, 2007 3:18 pm
Posts: 6
Emmanuel,

Im sorry if my last post looked like I was requesting you to provide the jar details, but what I was attempting to communicate was that Ive upgraded to both 3.2.0.cr2 and 3.30GA of hibernate-annotations and it did not appear to fix the problem.

Was hoping you could quanity what specific version of hibernate-annotations the fix was made so I could test.

Thanks again
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 3:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
My bad I read your initial post too fast.
Can you avoid the nullable=false constraint. I bet your column is generated post insertion (for SQL Server), and since Hibernate has no value to insert (it's generated), you have a clash.

Do you see a way to make it work in plain SQL (if nullable is still false)?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 22, 2007 10:41 am 
Newbie

Joined: Fri Feb 16, 2007 3:18 pm
Posts: 6
Thanks again for your response.

When we take the same approach using a hbm file, and bypass the annotations the generate works fine for this CreatedOn field. What would be the difference?

To answer your questions, if we allow this property to be null, Im fairly certain the insert statement would work, have not tested it. But, I would rather quantify that hibnerate-annotations can reproduce the hbm config file setting we have.

Thanks again
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 22, 2007 4:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
OK post both mappings in JIRA, I'll have to check why it's different.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 22, 2007 6:16 pm 
Newbie

Joined: Fri Feb 16, 2007 3:18 pm
Posts: 6
http://opensource.atlassian.com/project ... se/ANN-626

Thanks again for your help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.