我正在将我的应用程序更新为hibernate 5.2.x和Spring 4.3.x以及Spring数据JPA 1.11.x
我无法弄清楚当前的问题与许多因错误而失败的集成测试有关:
HHH000346: Error during managed flush [Session/EntityManager is closed]
(测试基于Arquillian /放心并且之前已经过去了。我在服务方法和存储库接口上使用@Transactional注释。) Spring发起的托管刷新似乎存在问题 - 好像我在服务方法结束时添加了一个手动调用flush(),测试通过了。
此处提供了hibernate + spring的完整跟踪日志示例:http://pastebin.com/LiEU7WAg
我希望有人可以从日志中识别导致实体管理器关闭的原因导致Hibernate错误被抛出。
编辑一个 以下是实体层次结构
@Audited
@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"group_id", "type"}))
public class GroupPreference extends AbstractPreference<GroupPreferenceType> {
@ManyToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "group_id")
@Index(name = "idx_group_pref_group_id")
private Group group;
@Enumerated(EnumType.STRING)
private GroupPreferenceType type;
}
@Audited
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name="preference")
public abstract class AbstractPreference<T extends Enum<T> & PreferenceType> extends Identifiable {
@CollectionTable(name = "preference_entry", joinColumns = {@JoinColumn(name = "preference_id")})
@ElementCollection(fetch = FetchType.LAZY)
@Column(name = "entry_value", length = ENTRY_VALUE_LENGTH)
@MapKeyColumn(name = "entry_key")
private Map<String, String> entries = new HashMap<>();
}
@MappedSuperclass
public abstract class Identifiable {
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2", parameters = {
@org.hibernate.annotations.Parameter(name = UUIDGenerator.UUID_GEN_STRATEGY_CLASS,
value="SequentialVersionOneStrategy")
})
private String id;
}
测试试图删除组首选项,该首选项在Spring数据CrudRepository中调用delete。