-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Using Criteria createAlias -
PostPosted: Mon Sep 17, 2012 6:32 pm 
Newbie

Joined: Thu Jun 28, 2012 12:52 pm
Posts: 3
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.