Hi,
I have a problem in hibernate's object consultation.
The problem is following:
I have a class named ProductClient and another named Client.
The atribute primary key of the Client class composes the composition key of the ProductClient class.
I need consultation every ProductClient of a Client.
For this, I used the following OQL sentence:
Code:
StringBuilder _hql = new StringBuilder();
_hql.Append("select pc ");
_hql.Append(" from ProductClient pc ");
_hql.Append(" where pc.Client.Id = " + _client.Id.ToString());
The method is return me every ProductClient of Table ProductClient and I wanted every ProductClient of a Client. When I try to read the value of the Client's Key, return me the following exception:
Code:
Object reference not set to an instance of an object.
When I remove the following restriction:
Code:
_hql.Append(" where pc.Cliente.Id = " + _cliente.Id.ToString());
the Client object's values return me without problems.
I also already tried the following sentence.
Code:
StringBuilder _hql = new StringBuilder();
_hql.Append("select pc ");
_hql.Append(" from ProductClient pc ");
_hql.Append(" inner join pc.Client c ");
_hql.Append(" where c.Id = " + _client.Id.ToString());
but It don't worked too.
Somebody could help me?
Thanks!
Luiz César Cherri