spring-jpa with hibernate and mysql 5.7(platform-bom-1.1.4.RELEASE):
实体定义:
@Entity
@Table(name="project")
public class ProjectEntity extends MDMBaseDescriptiveEntity
{
}

public class ActivityEntity extends MDMBaseDescriptiveEntity
{
// optional
@Column(name="project_id")
private Integer projectId;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="container_id")
private ActivityEntity container;
@OneToMany(mappedBy="container", cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
@OrderColumn(name="order")
private List<ActivityEntity> activities = new ArrayList<ActivityEntity>();
@Enumerated(EnumType.STRING)
private Activity.Type type;
@Enumerated(EnumType.STRING)
private Activity.Mode mode;
private String tag;
...
}
&#13;
存储库定义:
public interface IProjectDao extends JpaRepository<ProjectEntity, Integer>
{
}
&#13;
public interface IActivityDao extends JpaRepository<ActivityEntity, Integer>
{
List<ActivityEntity> findByContainerId(int containerId);
}
&#13;
按ID访问不存在的实体:
ProjectEntity pe = projectDao.getOne(9999999); 作为上述调用的结果,预期pe == null,它是。
ActivityEntity ae = activityDao.getOne(9999999); 作为上述调用的结果,预期ae == null,但ae!= null,即使其所有属性都具有默认值。在ae上调用getter时抛出javax.persistence.EntityNotFoundException。
为什么行为不同?