从祖先获取对象有什么变化吗?我有这些实体:
@Entity
@Table(name = "SPORT")
@DiscriminatorColumn(name = "sport_type", discriminatorType = DiscriminatorType.STRING, length = 32)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Sport implements Serializable {
@Column(name = "sport_type", insertable = false, updatable = false)
private String sportType;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@JoinColumn(name = "HEAD_ID", referencedColumnName = "IDENT")
@ToStringExclude
protected Headquaters headquaters;
}
@Entity
@DiscriminatorValue(Constants.COST_REPORT_CODE)
public class HandSport extends Sport {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "COST_TRADE_ID", referencedColumnName = "TRADE_ID")
private Playground Playground;
}
从这些实体我已经生成了这个元模型
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(HandSport.class)
public abstract class HandSport_ extends com.test.entity.Sport_ {
public static volatile SingularAttribute<HandSport, Playground> playground;
}
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(Sport.class)
public abstract class Sport_ {
public static volatile SingularAttribute<Sport, Headquaters> headquaters;
public static volatile SingularAttribute<Sport, String> id;
}
现在我只能拿到游乐场:
EntityGraph<HandSport> fetchGraph = entityManager.createEntityGraph(HandSport.class);
fetchGraph.addSubgraph(HandSport_.playground);
select.distinct(true);
TypedQuery<HandSport> typedQuery = entityManager.createQuery(select)
.setHint("javax.persistence.loadgraph", fetchGraph);
为什么我无法添加
fetchGraph.addSubgraph(Sport_.headquters);
如果我这样做,我可以看到编译错误:
"Cannot resolve method 'addSubgraph(javax.persistence.metamodel.SingularAttribute<com.test.entity.Sport, com.test.entity.Headquateres>)'"
从祖先那里获取值有什么变化吗?或者是否可以创建第二个FetchGraph并通过提示注册两个图形?
答案 0 :(得分:0)
JPA API在EntityGraph
类的各种方法中使用了泛型。
这是reported to the JPA "expert group"早在2015年,但他们并没有费心去解决它。
DataNucleus JPA发布了他们自己的JPA API jar,他们不久前为他们的用户做了修复,但是既然你正在使用Hibernate,那么这对你没有好处。