I searched the forums and jira for this, couldn't find an answer to this.
With mapped subclasses, it looks like foreign key names are based on foreign key names of the parent class/table (see DenormalizedTable.createForeignKeys()). The key names get longer and longer for each subclass. At three-levels of inheritance deep, this exceeds the name length limitation in sybase 12 (30 chars).
Below are the symptoms during a schema update, but I traced it to the creation of the foreign key names in the DenormalizedTable class.
What can I do about this other than hack the createForeignKeys() method?
Hibernate version:
3.1
Mapping documents:
Code:
<hibernate-mapping default-lazy="false">
<union-subclass name="com.xxx.demo.dataabstraction.domain.FixedRateMortgage" entity-name="com.xxx.demo.dataabstraction.domain.FixedRateMortgageI"
extends="com.xxx.demo.dataabstraction.domain.BondI">
<property name="poolId" type="java.lang.String" column="poolId"/>
<property name="poolType" type="java.lang.String" column="poolType"/>
</union-subclass>
</hibernate-mapping>
<hibernate-mapping default-lazy="false">
<union-subclass name="com.xxx.demo.dataabstraction.domain.Bond" entity-name="com.xxx.demo.dataabstraction.domain.BondI"
extends="com.xxx.demo.dataabstraction.domain.InstrumentI">
<property name="maturityDate" type="date" column="maturityDate"/>
<property name="coupon" type="double" column="coupon"/>
</union-subclass>
</hibernate-mapping>
<hibernate-mapping default-lazy="false">
<class name="com.xxx.demo.dataabstraction.domain.Instrument" entity-name="com.xxx.demo.dataabstraction.domain.InstrumentI"
>
<id name="id" column="id" type="long">
<generator class="assigned">
</generator>
</id>
<property name="issuer" type="java.lang.String" column="issuer"/>
<property name="productType" type="java.lang.String" column="productType"/>
<property name="displayName" type="java.lang.String" column="displayName"/>
<many-to-one name="fundamentalData" class="com.xxx.demo.dataabstraction.domain.FundamentalDataI" cascade="save-update,delete"/>
<property name="productSubType" type="java.lang.String" column="productSubType"/>
<property name="countryName" type="java.lang.String" column="countryName"/>
<many-to-one name="currency" class="com.xxx.demo.dataabstraction.domain.CurrencyI" cascade="save-update,delete"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
n/a
Full stack trace of any exception that occurs:
2006-09-13 16:02:43,124 WARN [main] hibernate3.LocalSessionFactoryBean (LocalSessionFactoryBean.java:993) - Unsuccessful schema statement: alter table FixedRateMortgageI add constraint FK75E8C12293F7EAA43d62dc6668f6f39 foreign key (fundamentalData) references FundamentalDataI
com.sybase.jdbc2.jdbc.SybSQLException: The identifier that starts with 'FK75E8C12293F7EAA43d62dc6668f6' is too long. Maximum length is 30.
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2846)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:2168)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:220)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:203)
at com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1702)
at com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:1685)
at com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:431)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.executeSchemaStatement(LocalSessionFactoryBean.java:989)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.executeSchemaScript(LocalSessionFactoryBean.java:961)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean$3.doInHibernate(LocalSessionFactoryBean.java:931)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:334)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.updateDatabaseSchema(LocalSessionFactoryBean.java:924)
Name and version of the database you are using:
Sybase 12
The generated SQL (show_sql=true):
alter table FixedRateMortgageI add constraint FK75E8C12293F7EAA43d62dc6668f6f39 foreign key
Debug level Hibernate log excerpt: