Implementing custom methods for H2 Embedded Database

If you want to use an Embedded database such as H2 to unit test your code, you will

need to implement your method manually in H2 if it doesn’t supply one out of the box.

You can use Jooq to do this this

public class H2NewIDImpl {
    public static int counter = 0;
    public static int NEWID() throws SQLException {
        // Translate your T-SQL statements to jOOQ statements (if any)
       return counter++;
    }
}

and the sql to pick up the above class

CREATE ALIAS NEWID
FOR "net.prashu.H2NewIDImpl.NEWID";

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.