Skip to content

Commit 6e5cb5e

Browse files
committed
Upgrade hsearch-with-elasticsearch to JDK 17 + Hibernate Search 6.2
1 parent 71d236d commit 6e5cb5e

File tree

8 files changed

+214
-220
lines changed

8 files changed

+214
-220
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ This repository contains demos used live during presentations or in blog posts;
2020
Accompanies the blog post https://in.relation.to/2019/11/12/hibernate-search-quarkus/
2121
- _hsearch-feature-examples_: Demonstrates various features of Hibernate Search 6 with Elasticsearch in Quarkus.
2222
Used in [Quarkus insights Episode 32](https://www.youtube.com/watch?v=hwxWx-ORVwM).
23-
- [OBSOLETE] _hsearch-with-elasticsearch_: Shows how to use the Elasticsearch backend in Hibernate Search 5.x.
24-
Used for the talk "From Hibernate to Elasticsearch in no Time" at JavaZone 2016.
23+
- _hsearch-with-elasticsearch_: Shows how to use the Elasticsearch backend in Hibernate Search 6.x.
24+
Used for the talk "From Hibernate to Elasticsearch in no Time" at JavaZone 2016 (back then it was using Hibernate Search 5.x).
2525
* Hibernate Validator
2626
- _threeten-extra-validator-example_: Constraint validators for ThreeTen Extra date/time types.
2727
Accompanies the blog post http://in.relation.to/2017/03/02/adding-custom-constraint-definitions-via-the-java-service-loader/

hibernate-search/hsearch-with-elasticsearch/pom.xml

Lines changed: 97 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,41 @@
1212
<description>Demonstrates how to use the Elasticsearch backend for Hibernate Search</description>
1313

1414
<properties>
15+
<compiler-plugin.version>3.11.0</compiler-plugin.version>
16+
<surefire-plugin.version>3.0.0</surefire-plugin.version>
1517
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1618
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
17-
<maven.compiler.source>1.8</maven.compiler.source>
18-
<maven.compiler.target>1.8</maven.compiler.target>
19+
<maven.compiler.release>17</maven.compiler.release>
1920

20-
<version.org.hibernate.search>5.11.3.Final</version.org.hibernate.search>
21-
<version.org.hibernate.orm>5.4.5.Final</version.org.hibernate.orm>
22-
<test.elasticsearch.host.version>5.6.8</test.elasticsearch.host.version>
21+
<version.org.hibernate.search>6.2.0.CR1</version.org.hibernate.search>
22+
<version.org.hibernate.orm>5.6.15.Final</version.org.hibernate.orm>
23+
24+
<docker-maven-plugin.version>0.34.1</docker-maven-plugin.version>
25+
<test.containers.run.skip>false</test.containers.run.skip>
26+
<test.elasticsearch.run.skip>false</test.elasticsearch.run.skip>
27+
<test.elasticsearch.run.image.name>elastic/elasticsearch</test.elasticsearch.run.image.name>
28+
<test.elasticsearch.run.image.tag>7.17.0</test.elasticsearch.run.image.tag>
2329
</properties>
2430

2531
<prerequisites>
26-
<maven>3.0</maven>
32+
<maven>3.9</maven>
2733
</prerequisites>
2834

2935
<dependencies>
3036
<!-- Compile -->
3137
<dependency>
32-
<groupId>org.hibernate</groupId>
33-
<artifactId>hibernate-search-orm</artifactId>
38+
<groupId>org.hibernate.search</groupId>
39+
<artifactId>hibernate-search-mapper-orm</artifactId>
3440
<version>${version.org.hibernate.search}</version>
3541
</dependency>
3642
<dependency>
37-
<groupId>org.hibernate</groupId>
38-
<artifactId>hibernate-search-elasticsearch</artifactId>
43+
<groupId>org.hibernate.search</groupId>
44+
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
3945
<version>${version.org.hibernate.search}</version>
4046
</dependency>
4147
<dependency>
4248
<groupId>org.hibernate</groupId>
43-
<artifactId>hibernate-entitymanager</artifactId>
49+
<artifactId>hibernate-core</artifactId>
4450
<version>${version.org.hibernate.orm}</version>
4551
</dependency>
4652

@@ -54,7 +60,7 @@
5460
<dependency>
5561
<groupId>com.h2database</groupId>
5662
<artifactId>h2</artifactId>
57-
<version>1.4.178</version>
63+
<version>2.1.214</version>
5864
<scope>test</scope>
5965
</dependency>
6066
<dependency>
@@ -67,10 +73,38 @@
6773

6874
<build>
6975
<plugins>
76+
<plugin>
77+
<artifactId>maven-compiler-plugin</artifactId>
78+
<version>${compiler-plugin.version}</version>
79+
<configuration>
80+
<compilerArgs>
81+
<compilerArg>-parameters</compilerArg>
82+
</compilerArgs>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<artifactId>maven-surefire-plugin</artifactId>
87+
<version>${surefire-plugin.version}</version>
88+
</plugin>
89+
<!-- This is only necessary because Hibernate Search
90+
never builds Jandex indexes for classes in the org.hibernate package -->
91+
<plugin>
92+
<groupId>org.jboss.jandex</groupId>
93+
<artifactId>jandex-maven-plugin</artifactId>
94+
<version>1.2.3</version>
95+
<executions>
96+
<execution>
97+
<id>make-index</id>
98+
<goals>
99+
<goal>jandex</goal>
100+
</goals>
101+
</execution>
102+
</executions>
103+
</plugin>
70104
<plugin>
71105
<groupId>org.apache.maven.plugins</groupId>
72106
<artifactId>maven-failsafe-plugin</artifactId>
73-
<version>2.19.1</version>
107+
<version>${surefire-plugin.version}</version>
74108
<executions>
75109
<execution>
76110
<goals>
@@ -84,24 +118,65 @@
84118
</executions>
85119
</plugin>
86120
<plugin>
87-
<groupId>com.github.alexcojocaru</groupId>
88-
<artifactId>elasticsearch-maven-plugin</artifactId>
89-
<version>5.11</version>
121+
<groupId>io.fabric8</groupId>
122+
<artifactId>docker-maven-plugin</artifactId>
123+
<version>${docker-maven-plugin.version}</version>
90124
<configuration>
91-
<clusterName>HibernateSearchDemoCluster</clusterName>
92-
<httpPort>9200</httpPort>
93-
<version>${test.elasticsearch.host.version}</version>
125+
<skip>${test.containers.run.skip}</skip>
126+
<startParallel>true</startParallel>
127+
<images>
128+
<image>
129+
<name>${test.elasticsearch.run.image.name}:${test.elasticsearch.run.image.tag}</name>
130+
<alias>elasticsearch</alias>
131+
<run>
132+
<skip>${test.elasticsearch.run.skip}</skip>
133+
<env>
134+
<logger.level>WARN</logger.level>
135+
<discovery.type>single-node</discovery.type>
136+
<!-- Limit the RAM usage.
137+
Recent versions of ES limit themselves to 50% of the total available RAM,
138+
but on CI this is sometimes too much, as we also have the Maven JVM
139+
and the JVM that runs tests taking up a significant amount of RAM,
140+
leaving too little for filesystem caches and resulting in freezes.
141+
-->
142+
<ES_JAVA_OPTS>-Xms1g -Xmx1g</ES_JAVA_OPTS>
143+
</env>
144+
<ports>
145+
<port>9200:9200</port>
146+
</ports>
147+
<log>
148+
<prefix>Elasticsearch: </prefix>
149+
<date>default</date>
150+
<color>cyan</color>
151+
</log>
152+
<wait>
153+
<http>
154+
<url>http://localhost:9200</url>
155+
<method>GET</method>
156+
<status>200</status>
157+
</http>
158+
<time>20000</time>
159+
</wait>
160+
</run>
161+
</image>
162+
</images>
94163
</configuration>
95164
<executions>
96165
<execution>
97-
<id>start-elasticsearch</id>
166+
<id>docker-start</id>
98167
<phase>pre-integration-test</phase>
99168
<goals>
100-
<goal>runforked</goal>
169+
<!-- Stops all images currently running before starting them again.
170+
Useful to stop processes still running from a previously failed integration test run.
171+
Because this is invoked before the start goal,
172+
this will stop all images defined in the configuration, not just those we will start.
173+
-->
174+
<goal>stop</goal>
175+
<goal>start</goal>
101176
</goals>
102177
</execution>
103178
<execution>
104-
<id>stop-elasticsearch</id>
179+
<id>docker-stop</id>
105180
<phase>post-integration-test</phase>
106181
<goals>
107182
<goal>stop</goal>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.hibernate.demos.hswithes.dto;
2+
3+
import java.util.Date;
4+
5+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FieldProjection;
6+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ProjectionConstructor;
7+
8+
public class VideoGameDto {
9+
10+
private final String title;
11+
private final String publisherName;
12+
private final Date release;
13+
14+
@ProjectionConstructor
15+
public VideoGameDto(String title, @FieldProjection(path = "publisher.name") String publisherName,
16+
Date release) {
17+
this.title = title;
18+
this.publisherName = publisherName;
19+
this.release = release;
20+
}
21+
22+
public String getTitle() {
23+
return title;
24+
}
25+
26+
public String getPublisherName() {
27+
return publisherName;
28+
}
29+
30+
public Date getRelease() {
31+
return release;
32+
}
33+
34+
@Override
35+
public String toString() {
36+
return "VideoGameDto [title=" + title + ", publisherName=" + publisherName + ", release=" + release + "]";
37+
}
38+
}

hibernate-search/hsearch-with-elasticsearch/src/main/java/org/hibernate/demos/hswithes/model/Character.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import javax.persistence.Id;
1515
import javax.persistence.ManyToMany;
1616

17-
import org.hibernate.search.annotations.ContainedIn;
18-
import org.hibernate.search.annotations.Field;
17+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
1918

2019
@Entity
2120
public class Character {
@@ -24,14 +23,13 @@ public class Character {
2423
@GeneratedValue
2524
public long id;
2625

27-
@Field
26+
@FullTextField
2827
public String nickName;
2928

30-
@Field
29+
@FullTextField
3130
public String specialPower;
3231

3332
@ManyToMany(mappedBy="characters")
34-
@ContainedIn
3533
public List<VideoGame> appearsIn = new ArrayList<>();
3634

3735
Character() {

hibernate-search/hsearch-with-elasticsearch/src/main/java/org/hibernate/demos/hswithes/model/Publisher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
import javax.persistence.Embeddable;
1010

11-
import org.hibernate.search.annotations.Field;
11+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
1212

1313
@Embeddable
1414
public class Publisher {
1515

16-
@Field
16+
@FullTextField
1717
public String name;
1818

19-
@Field
19+
@FullTextField
2020
public String address;
2121

2222
Publisher() {

hibernate-search/hsearch-with-elasticsearch/src/main/java/org/hibernate/demos/hswithes/model/VideoGame.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
import javax.persistence.Id;
1818
import javax.persistence.ManyToMany;
1919

20-
import org.hibernate.search.annotations.Field;
21-
import org.hibernate.search.annotations.Indexed;
22-
import org.hibernate.search.annotations.IndexedEmbedded;
20+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
21+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
22+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
23+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded;
2324

2425
@Entity
2526
@Indexed(index = "videogame")
@@ -29,24 +30,23 @@ public class VideoGame {
2930
@GeneratedValue
3031
public long id;
3132

32-
@Field()
33+
@FullTextField
3334
public String title;
3435

35-
@Field
36+
@FullTextField
3637
public String description;
3738

38-
@Field
39+
@GenericField
3940
public int rating;
4041

41-
@Field(name="release")
42+
@GenericField(name="release")
4243
public Date publishingDate;
4344

4445
@IndexedEmbedded
4546
public Publisher publisher;
4647

4748
@ElementCollection
48-
@Field
49-
@IndexedEmbedded
49+
@FullTextField
5050
public List<String> tags = new ArrayList<>();
5151

5252
@ManyToMany

hibernate-search/hsearch-with-elasticsearch/src/main/resources/META-INF/persistence.xml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@
2424
<property name="hibernate.show_sql" value="false" />
2525
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
2626

27-
<property name="hibernate.search.default.indexmanager" value="elasticsearch" />
28-
2927
<!-- Not needed if using localhost -->
30-
<!-- <property name="hibernate.search.default.elasticsearch.host" value="http://127.0.0.1:9200" /> -->
31-
32-
<property name="hibernate.search.default.elasticsearch.index_schema_management_strategy" value="CREATE" />
28+
<!-- <property name="hibernate.search.backend.uris" value="http://127.0.0.1:9200" /> -->
3329

34-
<!-- Allow start even on a Yellow status of the Elasticsearch cluster. This is common on single-node dev environments -->
35-
<property name="hibernate.search.default.elasticsearch.required_index_status" value="yellow" />
30+
<property name="hibernate.search.schema_management.strategy" value="create" />
3631

3732
<!-- Ensuring that Elasticsearch always returns up to date results makes testing much easier -->
38-
<property name="hibernate.search.default.elasticsearch.refresh_after_write" value="true" />
33+
<property name="hibernate.search.indexing.plan.synchronization.strategy" value="sync" />
3934
</properties>
4035

4136
</persistence-unit>

0 commit comments

Comments
 (0)