Hibernate字节码检测提取问题

时间:2017-05-11 14:15:49

标签: hibernate jpa fetch lazy-evaluation instrumentation

我使用org.hibernate.tool.instrument.javassist.InstrumentTask为使用maven-antrun-plugin的类应用了Hibernate字节码检测。类具有惰性@OneToOne关系,如下所示:

@Entity
@Table(name = "tableName", schema = "...", catalog = "...")
public class FirstClass {
  @Id
  @Column(name = "id")
  private long id;

  @LazyToOne(LazyToOneOption.NO_PROXY)
  @OneToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "secondClassId")
  private SecondClass secondClass;
//accessors
}

@Entity
@Table(name = "tableName", schema = "...", catalog = "...")
public class SecondClass {
  @Id
  @Column(name = "id")
  private long id;

//accessors
}

当我尝试使用Criteria或jpql获取属性secondClass时,我看到" secondClass"在查看调试之后检索数据并且没有secondClass数据(但应该是)。 查询:

SELECT FC FROM FirstClass FC JOIN FETCH FC.secondClass

为什么会这样?有人知道如何解决它吗?

0 个答案:

没有答案