Skip to content

perspilling/jdbi-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JDBI examples

This repo contains some example code used to try out using JDBI as a persistence framework in Java projects.

The domain model used in the examples looks like this:

| Team | ---> | Person | -(cascade)-> | Address |

Notes

CGLIB issue with references

JDBI generates boilerplate code from annotated interfaces or abstract classes. When using abstract classes it would be nice to di the following:

@RegisterMapper(AddressMapper.class)
public abstract class AddressAbstractClassJdbiDao implements AddressDao {
}

...

public Foo {
    private AddressDao addressDao = dbi.onDemand(AddressAbstractClassJdbiDao.class);
}

However, this doesn't work. You will get a null pointer exception. Instead you must use the abstract (implementation) class as reference, like this:

@RegisterMapper(AddressMapper.class)
public abstract class AddressAbstractClassJdbiDao implements AddressDao {
}

...

public Foo {
    private AddressAbstractClassJdbiDao addressDao = dbi.onDemand(AddressAbstractClassJdbiDao.class);
}

CGLIB issue with abstract classes

It seems that when using abstract classes with CGLIB you need to put them in a separate file, otherwise you get the following error:

java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
	at org.skife.jdbi.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:721)
	at org.skife.jdbi.cglib.proxy.Enhancer.generateClass(Enhancer.java:499)

About

Some examples of using JDBI as a persistence framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages