I\'m developing a new Java web application and I\'m exploring new ways (new for me!) to persist the data. I mostly have experience with JPA & Hibernate but, except for simpl
Since you want a simple and lightweight library and to use SQL, I can suggest take a look at fjorm. It allows you to use POJOs and CRUD operations without much effort.
Disclaimer: I'm an author of the project.
Not sure if it's a bit late. Maybe it's worth to have a try. Here is the solution provided by library abacus-jdbc:
Person person = Person.builder().firstName("jdbc").lastName("whoiam").build();
long personId = personDao.insert(person);
City city = new City(123, "Sunnyvalue");
int cityId = cityDao.insert(city);
Person person = Person.builder().firstName("jdbc").lastName("whoiam").build();
long personId = personDao.insert(person);
Address address = Address.builder().street("1130 Ky").cityId(cityId).state("CA").zipCode("95677").personId(personId).build();
addressDao.insert(address);
Person personFromDB = personDao.gett(personId);
System.out.println(personFromDB);
personDao.loadJoinEntitiesIfNull(personFromDB, Address.class);
System.out.println(personFromDB);
Basically you can do CRUD and a lot of more without writing single DAL/DAO method. All the DAO classes you need to define are:
public interface PersonDao extends JdbcUtil.CrudDao<Person, Long, SQLBuilder.PSC, PersonDao>,
JdbcUtil.JoinEntityHelper<Person, SQLBuilder.PSC, PersonDao> {
}
public interface AddressDao extends JdbcUtil.CrudDaoL<Address, SQLBuilder.PSC, AddressDao>,
JdbcUtil.JoinEntityHelper<Address, SQLBuilder.PSC, AddressDao> {
}
public interface CityDao extends JdbcUtil.CrudDao<City, Integer, SQLBuilder.PSC, CityDao> {
}
I know it doesn't address all your questions/problems. But at least it provides some alternative approaches for couple of your questions. If you need a framework which provides the extract features you asked, no doubt, that's Hibernate. But sometimes, if you want to control the db operations by a few very simple methods, rather than depend on a framework. Try abacus-jdbc. Here is all the sample code on Github
Disclaimer: I'm the developer of abacus-jdbc