I have 2 tables related by a column in Table1 which stores the Id of the object from Table 2 with the following format:
tableId:objectId -> Where tableId is a numeric value representing the id of Table 2 (not important for what I need) and objectId is a numeric value which is the id of the object in Table 2, very same as stored on column Id on Table 2.
This kind of ralations on BD can't be changed (they are mandatory for the project, though it would be much easier to have simple foreign keys).
Code:
CREATE TABLE TABLE1_CGRAD
(
ID NUMBER(8) NOT NULL,
CLASS_ID NUMBER(4),
DESCRIPTION VARCHAR2(30 BYTE),
ID_FP VARCHAR2(13 BYTE),
)
CREATE TABLE TABLE2_FPR
(
ID NUMBER(8) NOT NULL,
CLASS_ID NUMBER(4),
DESCRIPTION VARCHAR2(30 BYTE),
OFFSET NUMBER(4),
COND VARCHAR2(13 BYTE),
)
So in TABLE1_CGRAD.ID_FP = SOMENUMBER:TABLE2_FPR.ID
I have configured Hibernate xml with a custom read and write for the column TABLE1_CGRAD.ID_FP:
Code:
<hibernate-mapping package="com.pck.entities">
<class name="CGrad" table="TABLE1_CGRAD">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="classId" column="class_id"/>
<property name="description" column="descripcion"/>
<many-to-one name="fp" class="com.pck.entities.Fpr" unique="true" fetch="select" cascade="save-update">
<column name="id_fp"
write="concat('3090:', ?)"
read="SUBSTR(id_fp, INSTR(id_fp, ':', -1, 1)+1, LENGTH(id_fp)- INSTR(id_filtro_pir, ':', -1, 1))" />
</many-to-one>
</class>
</hibernate-mapping>
When I make hibernate use 2 select to get the two related objects from both tables, It works fine. But if I try to make hibernate use a Join Select to get the two objects at the same time, the custom read formula for the column id_fp is not applied (it makes the query simply with Table1.id_fp=Table2.id), so the select doesn't work. The same when trying to make a subcriteria for the column. Any idea why is this happenning?