我正在考虑实施反模式,因为@EntityListener
在某些情况下是不够的:
@MappedSuperclass
public abstract class AbstractEntity implements Serializable
{
...
public abstract AbstractEntity save(EntityManager em);
...
}
@Entity
public class ConcreteEntity extends AbstractEntity
{
...
public ConcreteEntity save(EntityManager em)
{
doSomeStuff(this);
ConcreteEntity merged;
if(id == null)
{
em.persist(this);
merged = this;
}
else
{
merged = em.merge(this);
}
doOtherStuff(merged);
return merged;
}
...
}
PRO:
CON:
em.persist(entity)
/ em.merge(entity)
还有别的我忘了吗?
答案 0 :(得分:2)
CON:
find...
- 方法呢?Contract
是使用某种技术来坚持自己。