假设我们有一个定义如下的实体:
public class Member extends User implements Comparable<Member> {
@ManyToMany
@JoinTable(name = "Friends")
@Filters({ @Filter(name = "deleted") })
private Collection<Member> friends = new HashSet<Member>();
}
并有一个名为deleted的过滤器,没有定义类似的参数
@FilterDef(name = "deleted", defaultCondition = "deleted = 0")
当我尝试将新元素添加到持久成员对象的朋友集合中时,就会出现问题。提交事务后,会出现以下异常。
org.hibernate.HibernateException: cannot recreate collection while filter is enabled: [domain.entity.Member.friends#98304]
at org.hibernate.action.internal.CollectionUpdateAction.execute(CollectionUpdateAction.java:74)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:291)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
任何想法我做错了什么?