我正在从Hibernate 3.x升级到最新的Hibernate 5.2.0 FINAL.在我的旧代码中,我们使用标准查询,如下所示.
Session session =getHibernateTemplate().getSessionFactory().getCurrentSession();
Criteria criteria = session.createCriteria(Employee.class);
criteria.add(Restrictions.eq("Department", department));
return criteria.list();
Run Code Online (Sandbox Code Playgroud)
现在,从Hibernate 5.2.0开始,不推荐使用createCriteria()方法.可以从以下文档中找到.
https://docs.jboss.org/hibernate/orm/5.2/javadocs/deprecated-list.html https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/SharedSessionContract.html#createCriteria -java.lang.Class-
文档建议使用JPA Criteria.以下是基于上述背景的几个问题.
由于我们没有使用EntityManager并且严重依赖于HibernateDAOSupport和HibernateTemplate,我如何使用session或sessionFactory来使用JAP Criteria?
如果我使用DetachedCriteria,如下面的代码片段,它将与以前的实现相同或下面的代码将给我们会话独立的结果?
DetachedCriteria criteria = DetachedCriteria.forClass(Employee.class);
criteria.add(Restrictions.eq("Department", department));
return (List<Employee>) getHibernateTemplate().findByCriteria(criteria);
Run Code Online (Sandbox Code Playgroud)另外,如果我以下面提到的方式使用DetachedCriteria,它将与我的旧代码具有相同的影响.
Session session =getHibernateTemplate().getSessionFactory().getCurrentSession();
DetachedCriteria criteria = DetachedCriteria.forClass(Employee.class);
criteria.add(Restrictions.eq("Department", department));
return criteria .getExecutableCriteria(session).list();
Run Code Online (Sandbox Code Playgroud)如果有更好的方法来处理这个请建议,因为我不想改变HibernateDAOSupport和HibernateTemplate的使用.
弹性搜索1.6
我想索引包含连字符的文本,例如U-12,U-17,WU-12,T恤......并且能够使用"简单查询字符串"查询来搜索它们.
数据样本(简化):
{"title":"U-12 Soccer",
"comment": "the t-shirts are dirty"}
Run Code Online (Sandbox Code Playgroud)
由于关于连字符的问题已经有很多,我已经尝试了以下解决方案:
使用Char过滤器:ElasticSearch - 在名称中使用连字符进行搜索.
所以我去了这个映射:
{
"settings":{
"analysis":{
"char_filter":{
"myHyphenRemoval":{
"type":"mapping",
"mappings":[
"-=>"
]
}
},
"analyzer":{
"default":{
"type":"custom",
"char_filter": [ "myHyphenRemoval" ],
"tokenizer":"standard",
"filter":[
"standard",
"lowercase"
]
}
}
}
},
"mappings":{
"test":{
"properties":{
"title":{
"type":"string"
},
"comment":{
"type":"string"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用以下查询完成搜索:
{"_source":true,
"query":{
"simple_query_string":{
"query":"<Text>",
"default_operator":"AND"
}
}
}
Run Code Online (Sandbox Code Playgroud)
什么有效:
"U-12","U*","t*","ts*"
什么行不通:
"U-*","u-1*","t-*","t-sh*",......
所以似乎char过滤器没有在搜索字符串上执行?我能做些什么来完成这项工作?
I have a spring boot application with mapstruct where I get this warning on the maven-compiler-plugin testCompile phase:
[WARNING] The following options were not recognized by any processor: '[mapstruct.suppressGeneratorTimestamp]'
As I don't want warnings in my code I have been searching to solve this issue but the only thing that worked this far is to use <showWarnings>false</showWarnings>
我应该怎么做才能解决此警告而不将其静音?
申请文件:
pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
</parent>
<groupId>com.example</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> …Run Code Online (Sandbox Code Playgroud)