我把我的应用从Spring Boot 2.2.5升级到2.3.3,使用了5.4.20.Final版本的Spring Data JPA starter。在编译时增强了我的实体。
现在,当我在覆盖JpaRepository的
尽管这个警告——图表已经被正确地获取,但是我只能在日志中看到一个SQL查询,并且应用程序的行为与更新之前相同。
这是我的存储库代码:
怎样解决这个警告?我可以看到这个警告是发生在 Hibernate 的
现在,当我在覆盖JpaRepository的
findAll
方法时,在@EntityGraph
注解中使用attributePaths
属性时,会出现如下警告:2020-08-19 12:13:41.121 WARN 9348 --- [nio-8060-exec-3] [] [] o.h.engine.internal.TwoPhaseLoad : Entity graph specified is not applicable to the entity [DictionaryLang(id=1601, name=null, lang=null)]. Ignored.
2020-08-19 12:13:41.483 WARN 9348 --- [nio-8060-exec-3] [] [] o.h.engine.internal.TwoPhaseLoad : Entity graph specified is not applicable to the entity [DictionaryValueLang(id=3051, lang=null, name=null)]. Ignored.
尽管这个警告——图表已经被正确地获取,但是我只能在日志中看到一个SQL查询,并且应用程序的行为与更新之前相同。
这是我的存储库代码:
public interface DictionaryRepository extends JpaRepository<Dictionary, Long>, QuerydslPredicateExecutor<Dictionary> {
@EntityGraph(attributePaths = {"langs", "values", "values.langs"})
@Override
Page<Dictionary> findAll(Predicate predicate, Pageable pageable);
}
以下是我的实体:
@Entity
@Table(name = "DICTIONARIES")
public class Dictionary {
@Id
@SequenceGenerator(name = "SEQ_DICTIONARIES", sequenceName = "SEQ_DICTIONARIES")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_DICTIONARIES")
private Long id;
@OrderBy("ordinal ASC")
@OneToMany(mappedBy = "dictionary", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<DictionaryValue> values;
@OneToMany(mappedBy = "dictionary", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private Set<DictionaryLang> langs;
}
@Entity
@Table(name = "DICTIONARY_LANGS")
public class DictionaryLang extends BaseEntity {
@Id
@SequenceGenerator(name = "SEQ_DICTIONARY_LANGS", sequenceName = "SEQ_DICTIONARY_LANGS")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_DICTIONARY_LANGS")
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@LazyToOne(LazyToOneOption.PROXY)
@JoinColumn(name = "DICTIONARY_ID")
private Dictionary dictionary;
}
怎样解决这个警告?我可以看到这个警告是发生在 Hibernate 的
TwoPhaseLoad
类的这些行中:GraphImplementor fetchGraphContext = session.getFetchGraphLoadContext();
if ( fetchGraphContext != null && !fetchGraphContext.appliesTo( entity.getClass() ) ) {
LOG.warnf( "Entity graph specified is not applicable to the entity [%s]. Ignored.", entity);
fetchGraphContext = null;
session.setFetchGraphLoadContext( null );
}
spring-boot-starter-parent
的版本从2.2.0.RELEASE
升级到2.3.2.RELEASE
,但没有更改任何代码,现在出现了这个问题。遵循@Seb的建议,在注释中定义EntityGraph.EntityGraphType.LOAD
也解决了我的问题。 - kscherrer