0

I learned that when I want to paging '@Embedded class's properties', I have to write down the code like

@Entity
public class DepEntity {
    @Embedded
    private ExpEntity exp;
}

@Embeddable
public class ExpEntity {
    @Column(name = "exp_total")
    private BigDecimal totalExp;
}
Sort sort = Sort.by("exp.totalExp").descending();
PageRequest pageRequest = PageRequest.of(0, 10, sort);
Page<DepEntity> depEntities  = depEntityRepository.findAll(pageRequest);

just like Sort.by("exp.totalExp").descending(), when I want to paging 'totalExp' property, I have to use it as 'exp.totalExp'.

My question is, how does spring know that totalExp is in ExpEntity? Does spring do string check? if so, where can I see that code?

I'm sorry about my bad english

Clifford
  • 88,407
  • 13
  • 85
  • 165
gj su
  • 11
  • 1

1 Answers1

0

When you are using the @Embedded annotation, Spring utilizes reflection to identify the type of the annotated field. In the scenario given, the DepEntity class incorporates an embedded instance of ExpEntity. If exp.totalExp is used in a query, Spring is aware that totalExp belongs to the ExpEntity class due to its @Embeddable annotation.

Using this data, Spring generates a SQL query that incorporates the appropriate table and column names for the ExpEntity and totalExp fields, respectively.