Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

derby 10.8.2.2 with sequences and currentvalue

 
Yvan Sand
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, actually we use oracle and would like to use derby as the embedded db for our junit testing.

now we have a problem with sequences and I haven't found a solution yet, maybe we use it the wrong way?! I hope somebody can help...

we have the following sql script which creates two sequences and two tables. after that we insert some data using the sequences, but there is something wrong with the currentvalue...



the problem is that when calling "next value for seq_type" the sequence is ok and is incremented by 1, but the currentvalue is wrong and contains the value 6? when the sequence reaches 6, the currentvalue changes to 11.

can someone telling me what's going on and how must the script looks like to work correctly with sequences?

we're using derby 10.8.2.2 for this tests.

thanks for helping!
 
Martin Vajsar
Sheriff
Pie
Posts: 3751
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though I'm not acquianted with derby, it seems to me that you're fetching the "current value" from some dictionary table. You should use proper SQL construct for that. If next value FOR seq_text is valid on derby to fetch next value from a sequence, I'd say that current value FOR seq_text should provide you with the current value for your transaction.

Edit: I was probably assuming too much. From a quick peek into Derby documentation it seems there is no support for the "current value" of the sequence. The construct you're using is mentioned on forums, but the value is obtained from a dictionary view and is not mentioned in docs. I think this works for someone by accident, Derby sequences apparently were not designed to provide current values. You'll probably need to store the "next value" into a variable and use it with both parent and child tables.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic