I'm trying to create a mapping to a lagacy database and I can't figure out how to get this one situation to work.
Java 1.4.2
DB: Sybase ASA 9
Hibernate 3
Below is my mapping to my flags table. Pretty staight forward.
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.imsi.shareholder.business.Flag" table="flags">
<composite-id>
<key-property name="tableName" column="table_name"/>
<key-property name="flagName" column="flag_name"/>
<key-property name="id" column="integer_value"/>
</composite-id>
<property name="description" type="string">
<column name="description" length="50" />
</property>
<property name="numericDescription" type="long">
<column name="numeric_desc" precision="10" scale="0" />
</property>
<property name="sortOrder" type="long">
<column name="sort_order" precision="3" scale="0" />
</property>
<property name="editable" type="boolean">
<column name="editable" precision="1" scale="0" />
</property>
<property name="inactive" type="boolean">
<column name="inactive" precision="1" scale="0" />
</property>
</class>
</hibernate-mapping>
In many other tables I want to make many-to-one references to flags. The problem is that the other tables only contain the integer_value key. The other two keys are basically constants. I was hoping the below mapping would work, but get a BadSqlGrammerException.
Code:
<many-to-one name="method">
<formula>'FUND'</formula>
<formula>'METHOD_ID'</formula>
<column name="method_id"/>
</many-to-one>
Code:
org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [] in task 'Hibernate operation'; nested exception is com.sybase.jdbc2.jdbc.SybSQLException: ASA Error -131: Syntax error near 'FUND' on line 1
Is what I'm trying to do possilbe with the formula tags? Or some other way?
I looked into possibily a custom parameterized user type, but I figured I'd ask here first. If a custom user type is the way to go, can someone point me to a good example?
Thanks,
Brett