I Am using hibernate and i have a Entity like
@Entity
@Table(name = "MyEntity")
Class MyEntity {
@Id
@GeneratedValue
private long id;
@Column(name = "NAME")
private String name;
//some more attributes here
@OneToOne
@JoinColumn(name = "PARENT_ID")
MyEntity parent;
}
I have one record in database
id | name | parent_id
125 | n1 | null
and when i am trying to get this record with hibernate Query
Select e.id,e.name,e.parent.name from MyEntity e where e.id =125
this query is returning me zero records.because the parent is null here, so is there any way to handle this kind of situation.
thanks in advc.
In your case Hibernate implicitly uses inner join that doesn’t return anything when one of the sides is
null.You can instruct Hibernate to use left outer join instead as follows: