Error in my hibernate request
Hello i have this HQL request and i have an error when I run it
My function:
public ProprietaireInt getProprietaireInt(String codeImmeuble, String annee) {
//Create connexion
Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
ProprietaireInt proprietaireInt = new ProprietaireInt();
try{
String query = "SELECT pi.siren,pi.codeSCI,pi.libSocieteInterne,pi.libSocieteNormalise,pi.codeDomainePilotage " +
"FROM ImmeubleFisc if" +
"JOIN proprietaireInt pi ON if.sirenProprietaire = pi.siren " +
"WHERE if.idImmeubleFisc.codeImmeuble = :codeImmeuble " +
"AND if.idImmeubleFisc.exerciceFiscal = :annee";
Query q = null;
q = session.createQuery(query);
q.setStr开发者_Python百科ing("codeImmeuble", codeImmeuble);
q.setString("annee", annee);
proprietaireInt = (ProprietaireInt) q.uniqueResult();
session.flush();
}
catch (Exception e)
{
System.out.println(e.getMessage()+" "+e.getStackTrace());
}
return proprietaireInt;
}
My errror :
2010-08-02 12:12:22,081 ERROR ast.ErrorCounter (ErrorCounter.java:33) - line 1:156: unexpected token: proprietaireInt
I am not sure if JOIN ON is supported (see HHH-16 and HHH-620) but, assuming ProprietaireInt
is an entity, I guess the JOIN
clause should be (note the uppercase first letter):
JOIN ProprietaireInt pi ...
Also since you're using projections (without a constructor expression), you'll get a Object[]
as result and I don't think the following will work:
proprietaireInt = (ProprietaireInt) q.uniqueResult();
From the reference documentation:
14.6. The select clause
...
Queries can return multiple objects and/or properties as an array of type
Object[]
:select mother, offspr, mate.name from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr
Or as a
List
:select new list(mother, offspr, mate.name) from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr
Or - assuming that the class Family has an appropriate constructor - as an actual typesafe Java object:
select new Family(mother, mate, offspr) from DomesticCat as mother join mother.mate as mate left join mother.kittens as offspr
See also
- 14.3. Associations and joins
- 14.4. Forms of join syntax
- 14.6. The select clause
精彩评论