从Spring Boot 2.0.0 M2升级到2.0.0 M6后,我的Hibernate拦截器实现不再起作用。
我以前的实现:
@Configuration
public class HibernateConfiguration extends HibernateJpaAutoConfiguration {
private HibernateStatisticsInterceptor hibernateStatisticsInterceptor;
public HibernateConfiguration(DataSource dataSource, JpaProperties jpaProperties, ObjectProvider<JtaTransactionManager> jtaTransactionManager, ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers, ObjectProvider<List<SchemaManagementProvider>> providers, HibernateStatisticsInterceptor hibernateStatisticsInterceptor) {
super(dataSource, jpaProperties, jtaTransactionManager, transactionManagerCustomizers, providers);
this.hibernateStatisticsInterceptor = hibernateStatisticsInterceptor;
}
@Override
protected void customizeVendorProperties(Map<String, Object> vendorProperties) {
vendorProperties.put("hibernate.session_factory.interceptor", hibernateStatisticsInterceptor);
}
}
Run Code Online (Sandbox Code Playgroud)
但是使用M5或M6时,HibernateJpaAutoConfiguration类已更改,并且不再扩展JpaBaseConfiguration。
我尝试为每个YAML配置文件添加拦截器,但是它不起作用。
我的拦截器:
@Component("hibernateStatisticsInterceptor")
public class HibernateStatisticsInterceptor extends EmptyInterceptor {
private static final long serialVersionUID = 5278832720227796822L;
private ThreadLocal<Long> queryCount = new ThreadLocal<>();
public void startCounter() {
queryCount.set(0l);
}
public …Run Code Online (Sandbox Code Playgroud) 我有一个MVC控制器,它以JSON返回联系人列表。在前端,我使用jquery datatables插件。前端有一个搜索字段,用于过滤实体列表。
我的实体:
@Entity
public class Contact implements Serializable {
protected final static Logger LOGGER = LoggerFactory.getLogger(Contact.class);
private static final long serialVersionUID = -3691953100225344828L;
@Id
@GeneratedValue(generator = "hibernate-uuid")
@Column(length = 36, unique = true)
private String id;
@Version
@JsonIgnore
private int version;
private String firstname;
private String lastname;
@ManyToOne
private Company company;
... GETTER/SETTER ...
}
Run Code Online (Sandbox Code Playgroud)
和
@Entity
public class Company implements Serializable {
protected final static Logger LOGGER = LoggerFactory.getLogger(Company.class);
private static final long serialVersionUID = -7863930456400256944L;
@Id
@GeneratedValue(generator …Run Code Online (Sandbox Code Playgroud)