-->
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.  [ 4 posts ] 
Author Message
 Post subject: Database identity column problem with Sybase 12
PostPosted: Sat Feb 26, 2005 10:20 am 
Newbie

Joined: Wed Feb 23, 2005 11:29 am
Posts: 9
I am getting error with database identity column in Sybase 12.x. The same works OK with Microsoft SQL Server 2000, so I am not sure if it is JDBC driver or Hibernate problem.

Hibernate version: 3.0 beta 4

Mapping documents:
<class name="xxx.entity.Name" table="T_NAME">
<id name="id" column="id">
<generator class="identity"/>
</id>
<property name="name" column="name"/>
</class>

Code between sessionFactory.openSession() and session.close():
Name name = new Name();
name.setName("Test");
session.save(name); // error is genrated by this method

Full stack trace of any exception that occurs:
org.hibernate.exception.GenericJDBCException: could not insert: [xyz.entity.Name]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1598)
at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1997)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:36)
at org.hibernate.impl.ActionQueue.execute(ActionQueue.java:240)
at org.hibernate.event.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:221)
at org.hibernate.event.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:148)
at org.hibernate.event.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:94)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:171)
at org.hibernate.event.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:31)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:160)
at org.hibernate.event.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:25)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:64)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:575)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:570)
at mytest.fts.entity.NameTest.testName(NameTest.java:29)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: java.sql.SQLException: [BEA][Sybase JDBC Driver]No rows affected.
at weblogic.jdbc.base.BaseExceptions.createException(Unknown Source)
at weblogic.jdbc.base.BaseExceptions.getException(Unknown Source)
at weblogic.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at weblogic.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1583)
... 29 more


Name and version of the database you are using:
Sybase 12.0

The generated SQL (show_sql=true):
insert into T_NAME (name) values (?)

Debug level Hibernate log excerpt:
448:12,369 DEBUG JDBCTransaction: begin
48:12,369 DEBUG AbstractBatcher: opening JDBC connection
48:12,369 DEBUG DriverManagerConnectionProvider: total checked-out connections: 0
48:12,369 DEBUG DriverManagerConnectionProvider: using pooled JDBC connection, pool size: 0
48:12,369 DEBUG JDBCTransaction: current autocommit status: false
48:12,369 DEBUG DefaultSaveOrUpdateEventListener: saving transient instance
48:12,369 DEBUG AbstractSaveEventListener: saving [xyz.entity.Name#<null>]
48:12,369 DEBUG AbstractSaveEventListener: executing insertions
48:12,385 DEBUG BasicEntityPersister: Inserting entity: xyz.entity.Name (native id)
48:12,385 DEBUG AbstractBatcher: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
48:12,385 DEBUG SQL: insert into T_NAME (name) values (?)
Hibernate: insert into T_NAME (name) values (?)
48:12,385 DEBUG AbstractBatcher: preparing statement
48:12,479 DEBUG BasicEntityPersister: Dehydrating entity: [xyz.fts.entity.Name#<null>]
48:12,479 DEBUG StringType: binding 'Test' to parameter: 1
48:12,494 DEBUG AbstractBatcher: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
48:12,494 DEBUG AbstractBatcher: closing statement
48:12,494 DEBUG JDBCExceptionReporter: could not insert: [xyz.entity.Name] [insert into T_NAME (name) values (?)]
java.sql.SQLException: [BEA][Sybase JDBC Driver]No rows affected.
at weblogic.jdbc.base.BaseExceptions.createException(Unknown Source)
at weblogic.jdbc.base.BaseExceptions.getException(Unknown Source)
at weblogic.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at weblogic.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1583)
at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1997)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:36)
at org.hibernate.impl.ActionQueue.execute(ActionQueue.java:240)
at org.hibernate.event.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:221)
at org.hibernate.event.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:148)
at org.hibernate.event.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:94)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:171)
at org.hibernate.event.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:31)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:160)
at org.hibernate.event.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:25)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:64)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:575)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:570)
at mytest.fts.entity.NameTest.testName(NameTest.java:29)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
48:12,510 WARN JDBCExceptionReporter: SQL Error: 0, SQLState: HY000
48:12,510 ERROR JDBCExceptionReporter: [BEA][Sybase JDBC Driver]No rows affected.
48:12,510 DEBUG NameTest: Rollback the transaction
48:12,510 DEBUG JDBCTransaction: rollback
48:12,526 DEBUG SessionImpl: transaction completion


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 26, 2005 5:07 pm 
Newbie

Joined: Wed Feb 23, 2005 11:29 am
Posts: 9
It also works with Sybase jConnect driver but I am using BEA's Sybase driver since it is Weblogic Server JDBC Certified (and Sybase jConnect driver is not in WebLogic 8.1 sp4).

SQL generated using Sybase jConnect driver:

Hibernate: insert into T_NAME (name) values (?)
select @@identity

SQL generated using BEA's Sybase driver:

Hibernate: insert into T_NAME (name) values (?)

39:45,783 JDBCExceptionReporter WARN: SQL Error: 0, SQLState: HY000
39:45,783 JDBCExceptionReporter ERROR: [BEA][Sybase JDBC Driver]No rows affected.

"select @@identity" is missing if I use BEA's Sybase driver.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 8:25 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
According to this [BEA] the BEA Sybase driver does have generated keys support and as far as I know the only way to obtain generated keys with either Sybase or MS SQL Server is to do a SELECT @@IDENTITY.

You can configure Hibernate to add the "SELECT @@IDENTITY" itself instead of using the driver's implementation of getGeneratedKeys() (there is an option in hibernate.properties, can't remember exactly), but if the BEA driver still doesn't work I would definitely choose the working driver over the certified one.

Alin,
The jTDS Project.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 9:19 pm 
Newbie

Joined: Wed Feb 23, 2005 11:29 am
Posts: 9
I set the following property but it still does not work.

<property name="jdbc.use_get_generated_keys">true</property>

For now, I'll use Sybase driver.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.