views:

341

answers:

2

Hi, I have a domain object say, SalesOrder which has a composite id called id, made of salesOrder id and repid which is contained in another class called SalesOrderID(which is serializable and implements equals and hashcode)

my question is when i want to query SalesOrder, session.createSQLQuery("FROM SalesOrder where id=:soID")

and soID is populated with salesorder id and repid. this failes no matter what.

can anyone please help me?

thanks

+2  A: 

It most likely fails because you're trying to create an SQL query. You should be using HQL instead:

 Query query = session.createQuery("from SalesOrder so where so.id=:id");
 query.setParameter("id", salesOrderID);
 query.list();

If this was a typo in your question and you are indeed using createQuery() method then please post the exception stack trace.

ChssPly76
Like ChssPly76 said, it's because you're creating a SQL query. You can do this with a SQL query if you want, but you'll have to use database table columns, and you'll have to map the result back to an entity. Best bet is to just use HQL.
Brian Yarger
A: 

I had an incorrect mapping in the database beans class. Sorry for all the trouble, learned my lesson, apologize for wasting ur times

codeModuler