I think I found a bug in Hibernate 3.5, because the code above works in 3.2.2 branch.
Whenever I have a @OneToOne relation in this fashion, entityManager is not able to find the entity. The find() method allways return null!!!!!!
Code:
@Entity
@Table(name = "cheque")
@TableGenerator(name = "chequeTG", table = "sequenciador", pkColumnName = "tabela", valueColumnName = "valor", allocationSize = 1)
public class Cheque implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "chequeTG")
@Column(name = "id", nullable = false)
private Long id;
..............
[color=#800000]@OneToOne(cascade={CascadeType.ALL},optional=true)
@PrimaryKeyJoinColumn(name="id",referencedColumnName="cheque_id")
private ChequeUso uso[/color];
..................
}
@Entity
@Table(name="cheque_uso")
public class ChequeUso implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name="cheque_id")
private Long id;
@ManyToOne
@JoinColumn(name="consumo_id")
private Consumo consumo;
@OneToOne
@JoinColumn(name="cheque_id")
private Cheque cheque;
@Column(name = "cheque_uso_valor")
private double usado;
}
em.find(Cheque.class, 1L) // always return null
If I remove the @OneToOne relation, find() return the entity.
This didnĀ“t happen with Hibernate 3.2.2.