I'm attempting a table-per-subclass mapping using a discriminator that is from a formula
Basically if the group type of the carrier is 1, then I need to get the product codes from 'CFG_PRODUCT_CODE', if the carrier group type is 0, then I want to get the product codes from CFG_RELOAD_PROD_CODE. I also plan on using this on inserts as well.
I get a stack trace when I run with this mapping. Debugging in the hibernate code it looks like it is looking for a discriminator value for the ProductCode class. It is abstract, so I wouldn't expect it needing a discriminator.
I'm dealing with a legacy DB and so I can't modify the table structures.
Any help is appreciated.
Jason
Hibernate 3.2 with oracle.
Code:
<class name="com.vincent.ProductCode" abstract="true" >
<composite-id>
<key-many-to-one name="carrier"/>
<key-many-to-one name="platform"/>
<key-many-to-one name="exspplat"/>
<key-property name="code"/>
</composite-id>
<discriminator formula="select a.sp_group_type from VINCENT.tbl_carrier a where CARRIER_ID = a.CARRIER_ID" type="integer"/>
<subclass name="com.vincent.PrepaidProductCode" discriminator-value="1">
<join schema="VINCENT" table="CFG_PRODUCT_CODE">
<key>
<column name="CARRIER_ID"/>
<column name="PLAT_ID"/>
<column name="EXSPPLAT_ID"/>
<column name="PRODUCT_CODE"/>
</key>
<property name="denomination" column="DENOMINATION"/>
</join>
</subclass>
<subclass name="com.vincent.BillpayProductCode" discriminator-value="0">
<join schema="VINCENT" table="CFG_RELOAD_PROD_CODE">
<key>
<column name="CARRIER_ID"/>
<column name="PLAT_ID"/>
<column name="EXSPPLAT_ID"/>
<column name="PRODUCT_CODE"/>
</key>
</join>
</subclass>
</class>
Code:
org.hibernate.MappingException: Could not format discriminator value to SQL string
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:307)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
at com.vincent.HibernateConnectionPool.init(HibernateConnectionPool.java:101)
at com.vincent.HibernateConnectionPool.getCurrentSession(HibernateConnectionPool.java:119)
at com.vincent.gwtapps.server.ProductCodeServicesImpl.getProductCodes(ProductCodeServicesImpl.java:25)
at com.vincent.gwtapps.server.ProductCodeServicesTestCase.testGetProductCodes(ProductCodeServicesTestCase.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at com.intellij.rt.execution.junit.IdeaTestRunner.doRun(IdeaTestRunner.java:94)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at com.intellij.rt.execution.junit.IdeaTestRunner.startRunnerWithArgs(IdeaTestRunner.java:22)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:118)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
Caused by: java.lang.NumberFormatException: For input string: "com.vincent.ProductCode"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.<init>(Integer.java:620)
at org.hibernate.type.IntegerType.stringToObject(IntegerType.java:55)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:300)
... 23 more