Freewind @ Thoughtworks scala java javascript dart 工具 编程实践 月结 math python english [comments admin] [feed]

(2011-09-13) EBean

广告: 云梯:翻墙vpn (省10元) 土行孙:科研用户翻墙http proxy (有优惠)

http://www.avaje.com/ebean

这个playframework邮件组里的一个热心朋友介绍给我的,因为我发了一个"I hate Hibernate"的信,他便把他使用的这个ORM介绍给了我,还把他们做的play插件源代码也发给了我,让我参考。在此表示感谢。

我大约得看了一下这个EBean,它和JPA很像,但是对其进行了简化:

– No Session Object (or UnitOfWork or EntityManager)

– No Attached or Detached Beans

– No merge(), persist(),  flush(), or clear().  Instead Ebean has save() and delete()

的确,这些设计是罪恶的根源,我每次用JPA/Hibernate出问题,都是用了它们或者没用它们。理解起来虽然不是非常难,但是它们规则太多了,一点误用就会产生错误或者性能问题。看来EBean果然有眼光。

增改:

ESimple e = new ESimple();

e.setName(“test”);

e.setDescription(“something”);

// will insert

Ebean.save(e);

e.setDescription(“changed”);

// this will update

Ebean.save(e);

查询:

// find a customer by their id

Customer customer = Ebean.find(Customer.class, 4);

// find a list…

List customers = Ebean.find(Customer.class)

.where().like(“name”, “Rob%“)

.orderBy(“name desc”)

.findList();

这种语法跟ActiveObjects挺像的。

文档有点长,有机会再研究一下。不过我还是稍稍觉得它有点麻烦,可能ActiveObjects更爽一些。

comments powered by Disqus