-->
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: HSQL for testing can't generate sequence?
PostPosted: Wed Oct 26, 2005 6:01 pm 
Newbie

Joined: Mon Dec 27, 2004 3:47 pm
Posts: 12
Hibernate version:3.0.5

So, in production, I'm using Oracle, and that works just fine, but for testing purposes I'm trying to use HSQL in memory, and it seems that when I run my test to saveOrUpdate(obj) it's trying to get the next sequence by calling "select next value for SEQ from dual.SEQ"
Any thoughts on why this is?

Anyway, here's the top of my stack trace:

Code:
    [junit] org.hibernate.exception.GenericJDBCException: could not get next sequence value
    [junit]    at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
    [junit]    at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
    [junit]    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    [junit]    at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
    [junit]    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:85)




and the actual SQL Exception:
Code:
    [junit] Caused by: java.sql.SQLException: Sequence not found: USER_SEQ in statement [select next value for user.USER_SEQ from dual_user.USER_SEQ]
    [junit]    at org.hsqldb.jdbc.Util.throwError(Unknown Source)
    [junit]    at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
    [junit]    at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
    [junit]    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:396)
    [junit]    at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:82)
    [junit]    at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:73)
    [junit]    ... 24 more


relevant part of hibernate properties:

Code:
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.jdbc.use_get_generated_keys=true


relevant part of HBM file:
Code:
        <id
            name="userId"
            type="java.lang.Long"
            column="USER_ID"
            >
            <generator class="sequence"><param name="sequence">USER_SEQ</param></generator>
        </id>

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 8:44 pm 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
You didn't say what version of HSQL your using but you might want to do some hunting around. It appears there have been changes in how sequences are supported by HSQL and the Hibernate HSQL dialect. The following link might get you started.

http://opensource2.atlassian.com/projects/hibernate/browse/HHH-608


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 10:40 am 
Newbie

Joined: Mon Dec 27, 2004 3:47 pm
Posts: 12
my version of hsql is 1.8.0.1
i believe that the "<generator class="sequence">" is using Oracle.
I was hoping there might be a way to override this at runtime as opposed to keeping a different set of hbm files only for my tests.
possible?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 11:09 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
<generator class-"sequence"> isn't oracle specific. I use it as well on DB2. This generator can be used with any database that supports sequences. The SQL dialect for the particular database is responsable for taking care of the details of how hibernate accesses the feature.

So after that long winded explanation to answer your question. Yes, you should not need to sets of mapping files. If I understand the code correctly and the comments in those posts I think you need to execute the following to statements against the HSQL database.

Code:
create table dual_<sequence name> (zero integer)
insert into dual_<sequence name> values (0)


This is in addition to creating th sequence itself with

Code:
create sequence <sequence name> start with 1


Hibernate uses this table to select against when trying to get the next value from the sequence. I'm not very familiar with the HSQL dialect so I couldn't say if this is documented anywhere. I cam to this conclusion from reading the code for the dialect and might be completely offbase.


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.