-->
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.  [ 1 post ] 
Author Message
 Post subject: Generator class sequence-identity
PostPosted: Mon Nov 10, 2008 2:54 pm 
Newbie

Joined: Mon Nov 10, 2008 2:37 pm
Posts: 1
Location: Argentina
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.6

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

Working with Hello World Example of "Java Persistency with Hibernate" book

JDK: 1.6.0
Hibernate: 3.2.6
Database Oracle: 9.2.0.8
Oracle JDBC Driver: 10.2.0.3.0

I modify the example to work with different id generator class.
With "increment" (like the example in the book) works fine.
With "sequence" works fine.
With "sequence-identity" give an error.

How can I use "sequence-identity" generator with this example?
I'm Oracle database administrator and I belive that this generator is the best for Oracle database.
It not use a DUAL virtual table to increment the sequence and use it directly in the INSERT sentence.
Thanks a lot.
Carolina.

Debug using "sequence" and "sequence-identity" generator:


================================
Debug with "sequence" generator
================================

<hibernate-mapping>
<class name="hello.Message" table="MESSAGES">
<id name="id" column="MESSAGE_ID">
<generator class="sequence">
<param name="sequence">MESSAGES_SEQ</param>
</generator>
</id>
....


Hibernate:
select
message0_.MESSAGE_ID as MESSAGE1_0_0_,
message0_.MESSAGE_TEXT as MESSAGE2_0_0_,
message0_.NEXT_MESSAGE_ID as NEXT3_0_0_
from
MESSAGES message0_
where
message0_.MESSAGE_ID=?
15:16:17,930 DEBUG LongType:133 - binding '13' to parameter: 1
15:16:17,946 DEBUG StringType:172 - returning 'Hello World' as column: MESSAGE2_0_0_
15:16:17,946 DEBUG LongType:166 - returning null as column: NEXT3_0_0_
Hibernate:
select
MESSAGES_SEQ.nextval
from
dual
Hibernate:
insert
into
MESSAGES
(MESSAGE_TEXT, NEXT_MESSAGE_ID, MESSAGE_ID)
values
(?, ?, ?)
15:16:17,946 DEBUG StringType:133 - binding 'Take me your leader (please)' to parameter: 1
15:16:17,946 DEBUG LongType:126 - binding null to parameter: 2
15:16:17,946 DEBUG LongType:133 - binding '14' to parameter: 3
Hibernate:
update
MESSAGES
set
MESSAGE_TEXT=?,
NEXT_MESSAGE_ID=?
where
MESSAGE_ID=?
15:16:17,962 DEBUG StringType:133 - binding 'Greetings Earthling' to parameter: 1
15:16:17,962 DEBUG LongType:133 - binding '14' to parameter: 2
15:16:17,962 DEBUG LongType:133 - binding '13' to parameter: 3

=========================================
Debug with "sequence-identity" generator
=========================================

<hibernate-mapping>
<class name="hello.Message" table="MESSAGES">
<id name="id" column="MESSAGE_ID">
<generator class="sequence-identity">
<param name="sequence">MESSAGES_SEQ</param>
</generator>
</id>
....

Hibernate:
select
message0_.MESSAGE_ID as MESSAGE1_0_0_,
message0_.MESSAGE_TEXT as MESSAGE2_0_0_,
message0_.NEXT_MESSAGE_ID as NEXT3_0_0_
from
MESSAGES message0_
where
message0_.MESSAGE_ID=?
13:09:39,644 DEBUG LongType:133 - binding '15' to parameter: 1
13:09:39,644 DEBUG StringType:172 - returning 'Hello World' as column: MESSAGE2_0_0_
13:09:39,644 DEBUG LongType:166 - returning null as column: NEXT3_0_0_
Hibernate:
insert
into
MESSAGES
(MESSAGE_ID, MESSAGE_TEXT, NEXT_MESSAGE_ID)
values
(MESSAGES_SEQ.nextval, ?, ?)
13:09:39,644 DEBUG StringType:133 - binding 'Take me your leader (please)' to parameter: 1
13:09:39,644 DEBUG LongType:126 - binding null to parameter: 2

13:09:39,785 ERROR JDBCExceptionReporter:78 - Falta el parámetro IN o OUT en el índice:: 3
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [hello.Message]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
...
Caused by: java.sql.SQLException: Falta el parámetro IN o OUT en el índice:: 3
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1742)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3334)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3423)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.id.SequenceIdentityGenerator$Delegate.executeAndExtract(SequenceIdentityGenerator.java:80)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
...


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

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.