dancantong wrote:
Hello everybody.
I'm using Hibernate in my proyect, and till now it has been working perfectly. But now, I have a problem doing a simple query. I have three mapped classes, called
TOPlanos, TOPlanosGMS and TOPlanosSAP, where TOPlanos has a one-to-one relation wich each one. TOPlanos has a property called idOrdenTrabajo and I need to find all TOPlanos
for a given idOrdenTrabajo. So I have written a very simple Hibernate Query that does
the search but I get an exception that tells it cannot find the column idOrdenTrabajo in the database. The strange thing is that this property is not mapped to that name column, it
is mapped to ordenes_trabajo_id_orden_trabajo column. It seems that it is searching for the column with the same name of the property, not for the name I have mapped in the .hbm to the database.
Here I put all the mapping and code data. I don't know if there is something wrong with
the mappings but I has been working correctly till I've tried that query.
Thank you in advance.
Regards.
Daniel.
Query query = session.createQuery("from TOPlanos where idOrdenTrabajo " +
"= :idOrdenTrabajo");
You need to add and use an alias for your object. Hibernate appears to assume that it's a DB column if it doesn't have an alias.
Try "from TOPlanos toplanos where toplanos.idOrdenTrabajo = :idOrdenTrabajo"