Note you should change your property names to start with lower case letter like code
instead of Code
. That's required when you are working with a lot of frameworks.
Once you have renamed your properties, try the following -
String query = "from products p where p.code=" + Code;
Also, as @Luiggi suggests in the comment always use parameters instead of concatenating strings. e.g.
String query = "from products p where p.code = :code";
Another advice is to make your class name start with upper case letter. e.g. Product
instead of products
.
Finally, your query would look like -
String query = "from Product p where p.code = :code";
Query q = session.createQuery(query);
q.setString("code", code);
Update
public products getProductDescription(String Code)
{
setSessionFactory();
Session session = factory.getCurrentSession();
session.beginTransaction();
String query = "from products p where p.code=:code";
Query q = session.createQuery(query); //query is already created here
q.setString("code", Code);
System.out.println(query);
//delete the line below
//products pr = (products)session.createQuery(q);
//add the lines below
List<products> l = (List<products>) q.list();
products pr = null;
if(!l.isEmpty()) {
pr = l.get(0);
}
session.close();
return pr;
}