0

I tried to follow an example of a book hibernate Chapter 17 SQL native so I summary, I would return an object XXX with a SQL query using Hibernate .. Here is my example

@Override
    public Composant FindComposantFRomXls(String comp, String fab) {
return (Composant) getSessionFactory().getCurrentSession().createSQLQuery("select * from composant where ref_composant='"+comp+" ' and fabricant =(select id_fabricant from fabricant where nom_fabricant ='"+fab+"')").addEntity(Composant.class);
    }

this is my error message

java.lang.ClassCastException: org.hibernate.internal.SQLQueryImpl cannot be cast to com.JEE.model.Composant

Adriano_jvma
  • 455
  • 2
  • 11
  • 20

1 Answers1

0
       return (Composant) getSessionFactory().getCurrentSession().
    createSQLQuery("select * from composant c where c.ref_composant=:param 
    and c.fabricant = (select id_fabricant from fabricant f where f.nom_fabricant =:param2)")
.addEntity(Composant.class)
   .setParameter("param", comp).setParameter("param2", fab).uniqueResult();

it works fine ....thanks mkyong

Adriano_jvma
  • 455
  • 2
  • 11
  • 20