Hibernate version:
2.x
Name and version of the database you are using:
Postgresql 7.4
Hello
Let's say I have a parent table with two fields : id as primary key,parent_name varchar as unique key, and a child table with two fields : id, parent_name varchar with a foreign key contraint referencing the column 'parent_name' in the parent table.
I know using a varchar instead of an int as a key is quite dirty (I could just use the parent id instead of the parent name in the child table), but I'm trying to figure out if the resulting problem is a hibernate bug or really a side effect from this bad table modelisation design :
If I try a getHibernateTemplate().find("from Child where parent_name = 'foo'"), I am getting the following exception :
UncategorizedSQLException: (Hibernate operation): encountered SQLException [Bad Integer foo]; nested exception is org.postgresql.util.PSQLException: Bad Integer foo
Ok, so afaik it assumes the table field parent_name is of type integer, however in the child hbm.xml, I have this :
<many-to-one
name="Parent"
class="Parent"
not-null="true"
>
<column name="parent_name" />
</many-to-one>
ant in the parent hbm.xml, I have this :
<property
name="parentName"
type="java.lang.String"
column="parent_name"
unique="true"
length="255"
/>
and :
<set
name="childs"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="parent_name"/>
</key>
<one-to-many
class="Child"
/>
</set>
it looks like it does not understand the <key> column is not an integer, but instead a string. I tried <column name=".." type="java.lang.String"> or a plain <type> marker, but the hbm.xml is getting parsing errors. If I try a straight object hql query (like getHibernateTemplate().find("from Child where this.Parent.parentName = 'foo'")), it does exactly the same integer error.
why is it assuming the parent_name should be an integer, and not a string ?
thanks :)
|