Joining fixed-length CHAR field with VARCHAR field
Description
I join 2 tables on join condition: table1.col1=table2.col2
col1 is NOT table1's PK, col2 is table1's PK
col1's type is CHAR(20), col2's type is VARCHAR(40)
I use Hibernate's Criteria API and it doesn't recognise the join condition and gives me 0 row.
I've trimmed the padding spaces by extending UserType but it doesn't work. Seems that it only works for retrieving a CHAR field, not joining it to another field.
It's not in my capacity to change the DB schema so I can't change the CHAR to VARCHAR.
environment: Windows XP, JDK 1.6.0_07, Hibernate 3, Oracle 10g
Thanks!
Attachments
1
Activity
Show:
Steve EbersoleMarch 21, 2011 at 7:09 PM
Bulk closing stale resolved issues
Will SumekarJuly 7, 2010 at 4:24 AM
Hi Gail Thanks for your prompt reply.
As you can see in the attached code, the returned class of type OracleCHAR is String, the same as the other field. So I think casting is not necessary.
I join 2 tables on join condition:
table1.col1=table2.col2
col1 is NOT table1's PK, col2 is table1's PK
col1's type is CHAR(20), col2's type is VARCHAR(40)
I use Hibernate's Criteria API and it doesn't recognise the join condition and gives me 0 row.
I've trimmed the padding spaces by extending UserType but it doesn't work. Seems that it only works for retrieving a CHAR field, not joining it to another field.
Code:
Criteria pq = session.createCriteria(Devices.class).createAlias("PrisProduct", "pp");
pq.add(Restrictions.eq(field, value.trim()));
Collection pc = pq.list();
The Devices.hbm.xml excerpt:
<property name="dieCode" type="com.st.wma.datalayer.hibernate.util.OracleCHAR">
<column name="DIE_CODE" length="20" not-null="true" unique="true" />
</property>
<many-to-one name="PrisProduct" class="com.st.wma.datalayer.hibernate.model.PrisProduct" column="DIE_CODE" not-null="true" insert="false" update="false">
</many-to-one>
The PrisProduct.hbm.xml excerpt:
<set name="devices" table="DEVICES">
<key column="CAM_PRODUCT"/>
<one-to-many class="com.st.wma.datalayer.hibernate.model.Devices"/>
</set>
OracleCHAR code is attached.
It's not in my capacity to change the DB schema so I can't change the CHAR to VARCHAR.
environment: Windows XP, JDK 1.6.0_07, Hibernate 3, Oracle 10g
Thanks!