I posted this originally on the jboss EJB forum and was to that I should post it here. I think I found a bug and would like to know if I should file this as a bug and, if so, under which jboss project. Here is the link to the post on the jboss EJB forum:
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=142635
I am using jboss app server 4.0.5 with the version of EJB3 that it ships with(I am currently unable to upgrade due to project scheduling issues). When I use SingleTableInheritance and a DiscriminatorFormula with string DiscriminatorValue's that are not the same length and have more that one when clause in my DiscriminatorFormula then hibernate appears to pad the the shorter DiscriminatorValues with spaces until they are the length of the longest DiscriminatorValue. They then get WrongClassExceptions when hibernate tries to resolve them to objects of the base class.
If I change the DiscriminatorValues to be all the same length then it works fine.
Here is an example of what does not work:
Code:
@DiscriminatorFormula("case when DEFININGORG in ('VAC', 'AMTS') then 'PROVIDER' when DEFININGORG='ST' then 'ST' else 'VENDOR' end")
class Category
{...}
@DiscriminatorValue("PROVIDER")
class ProviderCategory extends Category
{...}
@DiscriminatorValue("VENDOR")
class VendorCategory extends Category
{...}
@DiscriminatorValue("ST")
class STCategory extends Category
{...}
It can only load ProviderCategory as a Category but get a WrongClassException when loading any of the other ones. When I view the generated SQL in the logs, I notice that ST and VENDOR are padded with spaces until they are the length of PROVIDER
However this works for all of them:
Code:
@DiscriminatorFormula("case when DEFININGORG='ST' then 'S' when DEFININGORG in ('VAC', 'AMTS') then 'P' else 'V' end")
class Category
{...}
@DiscriminatorValue("P")
class ProviderCategory extends Category
{...}
@DiscriminatorValue("V")
class VendorCategory extends Category
{...}
@DiscriminatorValue("S")
class STCategory extends Category
{...}
Here is the stacktrace:
Code:
DEBUG [SocketServerInvokerThread-172.16.200.111-0][2008-09-18 10:40:50,914][com.squaretrade.category
.CategoryManagerSessionImpl] CategoryManagerSessionImpl.java(114): CAUGHT EXCEPTION WHEN LOOKING UP
CATEGORY
javax.persistence.PersistenceException: org.hibernate.WrongClassException: Object with id: EBAY_1314
_61 was not of the specified subclass: com.squaretrade.category.Category (Discriminator: VENDOR )
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManag
erImpl.java:647)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:99)
at com.squaretrade.category.CategoryManagerSessionImpl.loadCategory(CategoryManagerSessionIm
pl.java:101)
at com.squaretrade.category.CategoryManagerSessionImpl.loadCategory(CategoryManagerSessionIm
pl.java:129)
at com.squaretrade.category.CategoryManagerSessionImpl.loadObject(CategoryManagerSessionImpl
.java:50)
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 org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor
.java:63)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedE
ntityManagerInterceptor.java:54)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:46)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor
.java:62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.remoting.ReplicantsManagerInterceptor.invoke(ReplicantsManagerIntercept
or.java:51)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.jav
a:77)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationIntercepto
r.java:102)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:1
06)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:263)
at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandl
er.java:82)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:398)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
Caused by: org.hibernate.WrongClassException: Object with id: EBAY_1314_61 was not of the specified
subclass: com.squaretrade.category.Category (Discriminator: VENDOR )
at org.hibernate.loader.Loader.getInstanceClass(Loader.java:1444)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1275)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
... 39 more