Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 8ddb376

Browse files
christophstroblsdeleuze
authored andcommitted
Add missing hints to support maintaining order in an element collection (jpa, hibernate).
1 parent a7d117d commit 8ddb376

File tree

2 files changed

+26
-0
lines changed
  • samples/data-jpa/src/main/java/app/main/model
  • spring-native-configuration/src/main/java/org/springframework/boot/autoconfigure/orm/jpa

2 files changed

+26
-0
lines changed

samples/data-jpa/src/main/java/app/main/model/Foo.java

+7
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121
import org.springframework.data.annotation.LastModifiedDate;
2222

2323
import javax.persistence.CascadeType;
24+
import javax.persistence.ElementCollection;
2425
import javax.persistence.Entity;
2526
import javax.persistence.EntityListeners;
2627
import javax.persistence.Enumerated;
2728
import javax.persistence.GeneratedValue;
2829
import javax.persistence.GenerationType;
2930
import javax.persistence.Id;
3031
import javax.persistence.OneToOne;
32+
import javax.persistence.OrderBy;
3133
import java.time.Instant;
34+
import java.util.List;
3235

3336
@EntityListeners(AuditingListener.class)
3437
@Entity
@@ -51,6 +54,10 @@ public class Foo {
5154
@LastModifiedBy
5255
String modifiedBy;
5356

57+
@OrderBy
58+
@ElementCollection
59+
private List<String> phoneNumbers;
60+
5461
public Foo() {
5562
}
5663

spring-native-configuration/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaHints.java

+19
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@
8484
// These three are due to org.hibernate.hql.internal.ast.util.TokenPrinters
8585
HqlTokenTypes.class, SqlTokenTypes.class, GeneratedOrderByFragmentRendererTokenTypes.class,
8686
}, access = TypeAccess.DECLARED_CONSTRUCTORS),
87+
@TypeHint(
88+
/* Required types to support maintaining order in element collection.
89+
*
90+
* @OrderBy
91+
* @ElementCollection
92+
* private List<String> phoneNumbers;
93+
*/
94+
types = {
95+
org.hibernate.sql.ordering.antlr.NodeSupport.class,
96+
org.hibernate.sql.ordering.antlr.OrderByFragment.class,
97+
org.hibernate.sql.ordering.antlr.SortSpecification.class,
98+
org.hibernate.sql.ordering.antlr.SortKey.class,
99+
org.hibernate.sql.ordering.antlr.OrderingSpecification.class,
100+
org.hibernate.sql.ordering.antlr.CollationSpecification.class
101+
},
102+
typeNames = {
103+
"antlr.CommonAST",
104+
"antlr.CommonToken",
105+
}),
87106
@TypeHint(types = {
88107
Id.class, GeneratedValue.class, Repository.class,
89108
PersistenceContext.class, MappedSuperclass.class, Column.class, ManyToOne.class, OneToMany.class,

0 commit comments

Comments
 (0)