我有一个应用程序,它使用JPA继承加载Profile。
我可以根据类型以多态方式加载它,但我希望能够在某些情况下加载特定配置文件的惰性字段(例如Employer的“jobs”)。
是否可以通过@NamedEntityGraph使用继承加载惰性字段?
您能为这种情况推荐更好的解决方案吗?
我有以下实体:
@Entity
@Table(name="profile")
@Inheritance(strategy = InheritanceType.JOINED)
public class Profile {
...
}
@Entity
@Table(name = "employer")
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
public class Employer extends Profile {
...
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name="employer_id")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Set<Job> jobs;
...
}
@Entity
@Table(name = "candidate")
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
public class Candidate extends Profile {
...
}
以下回购:
@Repository
public interface ProfileRepo extends CrudRepository<Profile, Long>{
Profile findOneProfileByUserId(long userId);
}