I'm trying to use the Criteria createAlias method to add a Restriction to the list of results that I return.
Here's the relevant part of the model:
Code:
@Table(name = "INDIVIDUAL")
public class Individual {
@Column(name = "PATIENT_ID", unique = true)
private String patientId;
@OneToMany(mappedBy = "individual", cascade = javax.persistence.CascadeType.ALL)
private Collection<Phenotype> phenotypes = new HashSet<Phenotype>();
...
}
Code:
@Table(name = "PHENOTYPE")
public class Phenotype implements Securable {
@ManyToOne
@JoinColumn(name = "INDIVIDUAL_FK")
private Individual individual;
...
}
And in my IndividualDaoImpl, I have am attempting to return a collection of individuals based on some query parameters. It works when I simply have Restrictions being added to the Criteria (ie. restrictions based on fields inside the Individual class such as patientId), but not when I attempt to use "createAlias" to search the collection of phenotypes that each Individual has.
Code:
Criteria criteria = session.createCriteria(Individual.class);
criteria.createAlias( "phenotypes", "phenotypes" ).add( Restrictions.like( "phenotypes", "%" + val + "%") );
where "val" is a string that we are looking for in phenotypes. Eg. val="cra" should return the phenotype "cranium".
I get this error:
WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 07001
ERROR org.hibernate.util.JDBCExceptionReporter - No value specified for parameter 2
So, I'm not sure what parameter 2 is, and I'm not sure if I'm using createAlias correctly. Would appreciate any suggestions! Thanks.