Madmike's Blog

September 8, 2009

How to generate Sequences in Mysql 5.1+ part 2

Filed under: Java,Mysql — Florescu Radu @ 19:40
Tags: , , ,

Second option is to use an orm for java :Hibernate with Spring or not .

There are some options you can use:

Use this node in your xml configurations file for your mapped table from database.

<generator class=”name”/>

Where class may be increment with the usual meaning, identity (the identity column of one table), hilo (a generator of random HiLow long with a complicated algorithm).
Soon I will post a working example here.

More informations you could find on RoseIndiaTUTORIALS

September 7, 2009

How to make sequences in MySql 5.1+

Filed under: Java,Mysql — Florescu Radu @ 20:10
Tags: , ,

Mysql doesn’t support sequences as Oracle and MsSQL.But we can simulate this using some implementations i found over the internet and improuved.

There are 2 options to do this thing:

1.Using an auxiliary table named sequence

  • create a table named sequence in your database
  • table sequence (id:BIGINT)
  • set the id with value equal to your start value (default)
  • every time you need a new id execute a transaction like this

select id from sequence

update sequence set id=id+1

  • every time a thread asks for an id a distinct long will be auto incremented

This procedure was tested on multiple threads concurrently(over 1000000),it depends on your settings of your MySql.

Create a free website or blog at WordPress.com.