浏览 1021 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
最后更新时间:2008-02-01
看到了段代码,贴出来聊聊
public class Persistent implements Lifecycle, Validatable, Serializable {
protected Long _id;
protected int _version;
protected boolean _versionCheckRequired;
public Long getIdentifier() {
return _id;
}
public void setIdentifier(Long id) {
_id = id;
}
public int getVersion() {
return _version;
}
public void setVersion(int version) {
_version = version;
}
public Long persist() throws HibernateException, SQLException {
HibernateSession.currentSession().saveOrUpdate(this);
return _id;
}
public void delete() throws HibernateException, SQLException {
HibernateSession.currentSession().delete(this);
}
public void refresh() throws HibernateException, SQLException {
HibernateSession.currentSession().load(this, _id);
}
public void lock() throws HibernateException, SQLException {
HibernateSession.currentSession().lock(this, LockMode.UPGRADE);
}
public void checkVersion(int version) throws StaleObjectException {
if (version != _version) {
throw new StaleObjectException();
}
_versionCheckRequired = false;
}
public boolean onSave(Session s) throws CallbackException {
return NO_VETO;
}
public boolean onDelete(Session s) throws CallbackException {
return NO_VETO;
}
public boolean onUpdate(Session s) throws CallbackException {
return NO_VETO;
}
public void onLoad(Session s, Serializable id) throws CallbackException {
_versionCheckRequired = true;
onLoad(s, (Long) id);
}
protected void onLoad(Session s, Long id) throws CallbackException {
}
public void validate() throws ValidationFailure {
if (_versionCheckReqired) {
throw new ValidationFailure("version check is required");
}
}
}
怎么样!? 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
最后更新时间:2008-01-10
多个操作需要事务时,事务怎么处理?
|
|
| 返回顶楼 | |
|
最后更新时间:2008-01-11
一直未能理解事务,这个词一点都不直观,啥叫事务啊?
是指rollback那一块的东西吗? |
|
| 返回顶楼 | |
|
最后更新时间:2008-01-11
我爱罗:)
你可以google一下,事务,了解一下事务的定义。 |
|
| 返回顶楼 | |
|
最后更新时间:2008-01-12
google了,的确是rollback相关的概念。
这个不影响,因为 事务是在 service层定义的东西,service层控制 session的 beginTransaction和 Model中只管 HibernateSession.currentSession().doSomthing(this); |
|
| 返回顶楼 | |
|
最后更新时间:2008-01-13
的确是与事务无关。不过这种做法也不是新鲜的,以前的帖子有讨论过用Java实现Rails那样的风格的CURD不难。只要你可以忍受在实体里有Hibernate的API,这个时候你的实体已经不POJO了。。需要POJO吗?不需要POJO吗?个人喜好吧。
|
|
| 返回顶楼 | |
|
最后更新时间:2008-01-13
是啊,不是pojo了
在SOA的系统架构中,POJO还是很必要的 |
|
| 返回顶楼 | |






