I have some doubts about how to make a hbm.xml file for a mapping in Hibernate. The problem comes when mapping a Java object which has fields in several tables.
The custom framework we are using requires to have a hbm.xml file for each object, but in this case its fields are in three tables, so I want to make a native SQL query (another requirement from above) and move the field values in the result over the new object described in the Hibernate mapping file.
My hibernate mapping file is something like:
<hibernate-mapping>
<class name="com.mycompany.myproject.model.scommons.companhiaalmacen.CompanhiaAlmacen" table="COMPANHIA_ALMACEN">
<id name="companyWarehouseId" type="java.lang.Integer" access="field">
<column name="ID_EMPRESA_NAVE" />
<generator class="assigned" />
</id>
<property name="companyId" type="java.lang.Integer">
<column name="ID_EMPRESA" />
</property>
<property name="warehouseDCId" type="java.lang.Integer">
<column name="ID_CENTRO_DISTRIBUCION_NAVE" />
</property>
<!-- HERE: This attribute NOMBRE_COMERCIAL belongs not only to another table (EMPRESA) -->
<!-- but also to another schema (GENERAL) as well -->
<property name="name" type="java.lang.String">
<column name="NOMBRE_COMERCIAL" />
</property>
<property name="creationDate" type="java.util.Date">
<column name="FECHA_ALTA" />
</property>
<property name="creationUser" type="java.lang.String">
<column name="USUARIO_ALTA" />
</property>
</class>
</hibernate-mapping>
I don't know how to make this without making a oneToMany or ManyToOne. I don't want Hibernate to retrieve the object and its mapped entities because I want to get this from my own db2 query.
Anyone knows how to do it or where can I look for this, please? (I already have looked for the SQLQuery in the Hibernate API, is just the mapping which I don't get).
Thank you in advance.