问题
I'm currently working on a game server for a turn-based persistent world game primarily targeted at smartphones, and I'm currently beginning to implement the persistence layer and I'm looking for some tips/advice.
I originally planned to use mybatis for the persistance layer and the mybatis-guice addon implemented a simple @Transactional annotation that is similar to Spring's but without the weight of that entire framework. Unfortunately I ditched mybatis since I found I was fighting with the ORM too much and my relational design doesn't normalize particularly well. Now I'm basically using JDBC and I'm really trying to avoid writing tons of boilerplate code for managing transactions and connections within a string of DAO calls.
I'm also avoiding using any application server here or adding using spring since they don't seem to fit in, the server runs in straight up java on top of netty. Given these conditions are there any simple transaction managers or am I stuck trying to roll my own? Something like mybatis-guice's @Transactional would be great.
回答1:
Spring and Hibernate combination is best IMO both are quite light depending on your needs.
Currently we are using OpenJPA and quite happy with that too.
How light does it need to be ?? Go with Spring and Hibernate they are light. Guice is simple and light weight DI framework which I am sure you are aware of but by adding on stuff like transaction management etc you will end up with too many lower end opensource products*(I am not saying that Guice is lower end by any means)* which you will find are not any lighter than other opensource alternatives and will have less community support since not many people will be using them.
回答2:
If you are looking for a better way to do database work without going for a full-blown ORM, you might look at JDBI. It is a very light wrapper around JDBC that fixes a lot of the warts, omissions, and hair-pulling moments.
来源:https://stackoverflow.com/questions/7883742/lightweight-java-transaction-management