-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL to get next value in a sequence.
PostPosted: Fri May 11, 2007 8:52 am 
Beginner
Beginner

Joined: Tue Apr 24, 2007 12:53 pm
Posts: 28
I've searched the forums for an answer to this question, and all the posts suggest that you identify the sequence in your HBM files to auto-insert the values prior to database insert.

Unfortunately that won't work for what I'm trying to accomplish.

Situation:

I am maintaining an application which in production uses DB2. I need to write unit tests for the database manipulation classes. So to ensure no changes to an actual database, I've written up DBUnit tests backed by a HSQLDB data source.

One of the tables i need to create a test for uses a Sequence for one of the columns in the primary key. With Hibernate HBM files, you can not define a sequence on a column unless it is a single-column PK.

The current, working method uses a straight SQL statment to get the next sequence for the required column. I need to convert this to HQL so it will work for both DB2 & HSQLDB.

Does anyone know how you accomplish this? Currently, when running the command against an HSQLDB I get an SQLException ("Statement does not generate a result set").

Any thoughts?

-B


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 9:01 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
If you make your JUnit tests extend Spring's AbstractTransactionalDataSourceSpringContextTests then all your tests become transactional and will get rolled back when you are finished, so your database will always start and stay the same.
Hope that helps.

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject: RE: AbstractTransactionalDataSourceSpringContextTests
PostPosted: Fri May 11, 2007 9:11 am 
Beginner
Beginner

Joined: Tue Apr 24, 2007 12:53 pm
Posts: 28
Unfortunately it doesn't. The select for the nextval in the Sequence is in the method being tested, not the test class. The test continuously fails because of the exception being thrown.

The need is to convert the SQL to HQL to eliminate the exception and validate that the insert occurs correctly.


Thanks for the bit of info though. It'll probably come in handy here very soon.

-B


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.