Monday, April 11, 2011

Derby sequence with Hibernate







Derby sequence

CREATE SEQUENCE MD_USER_SEQ
AS INT
START WITH 1;


Hibernate mapping to get User_id from sequence

<id name="userId" type="integer" column="USER_ID" >
<generator class="sequence">
<param name="sequence">MD_USER_SEQ</param>
</generator>
</id>

[update:]
after all there is an issue with DerbyDialect of hibernate.
So need the following fix. 



package entity;


import org.hibernate.dialect.DerbyDialect;


/**
 *
 * @author Srinath
 */
public class MyDerbyDialect extends DerbyDialect{


    @Override
public String getSequenceNextValString(String sequenceName) {
        return "values next value for " + sequenceName;
}
}


Then in hibernate config

  <property name="hibernate.dialect">entity.MyDerbyDialect</property>




Share Article : Derby sequence with Hibernate
Share/Save/Bookmark

3 comments:

canei said...

Thank you so much, Srinath :-)

It works perfect!

Srinath Gamage said...

You are welcome, Nice to hear that :)

Cegonsoft said...

You are provided only the hibernate code. But, if you may provided the steps for execute the hibernate programs, Really helpful for me. Srinath..
Cegonsoft

Post a Comment