Problem: hql query retruns null or empty result while sql corresponding query returns some resultsets. If the target hibernate Java Bean have an EmbeddedId be sure that the AttributeOverrides didn’t include a nullable column attribute. If so remove these nullable columns attributes from embedded id and put them directly in the bean as Bean variable properties. And this will fix problem
@Entity
@Table(name="WITR_MARIAGE", uniqueConstraints = @UniqueConstraint(columnNames={"CUSTOMER_ID", "WITR_HUSBAND_ID", "WITR_WIFE_ID"}) )
public class WitrMariage implements java.io.Serializable {
private WitrMariageId id;
private WitrHusband witrHusband;
private WitrWife witrWife;
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name="customerId", column=@Column(name="CUSTOMER_ID", nullable=false, precision=22, scale=0) ),
@AttributeOverride(name="witrHusbandId", column=@Column(name="WITR_HUSBAND_ID", nullable=false, precision=22, scale=0) ),
@AttributeOverride(name="witrWifeId", column=@Column(name="WITR_WIFE_ID", nullable=false, precision=22, scale=0) ),
@AttributeOverride(name="sort", column=@Column(name="SORT", precision=22, scale=0) ) } )
public WitrMariageId getId() {
return this.id;
}
public void setId(WitrMariageId id) {
this.id = id;
}
/*
* WitrHusband getter & setter
* WitrWife getter & setter
*/
}
@Entity
@Table(name="WITR_MARIAGE", uniqueConstraints = @UniqueConstraint(columnNames={"CUSTOMER_ID", "WITR_HUSBAND_ID", "WITR_WIFE_ID"}) )
public class WitrMariage implements java.io.Serializable {
private WitrMariageId id;
private WitrHusband witrHusband;
private WitrWife witrWife;
private long sort;
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name="customerId", column=@Column(name="CUSTOMER_ID", nullable=false, precision=22, scale=0) ),
@AttributeOverride(name="witrHusbandId", column=@Column(name="WITR_HUSBAND_ID", nullable=false, precision=22, scale=0) ),
@AttributeOverride(name="witrWifeId", column=@Column(name="WITR_WIFE_ID", nullable=false, precision=22, scale=0) ) } )
public WitrMariageId getId() {
return this.id;
}
public void setId(WitrMariageId id) {
this.id = id;
}
/*
* WitrHusband getter & setter
* WitrWife getter & setter
* sort getter & setter
*/
}