-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Possible bug related to DiscriminatorFormula
PostPosted: Mon Sep 22, 2008 3:50 pm 
Newbie

Joined: Fri Mar 10, 2006 8:52 pm
Posts: 5
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2008 10:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I just tried to reproduce your problem with one of the test cases of the latest annotations versions. It seems to work.
It stil could be a a bug specific to a given version. Which version are you using (Annotations and Core)? It could also be some database specific feature. What db are you using?

Have you turned on Hibernate SQL trace. It would be interesting to see what SQL Hibernate generates and how the result looks like. You can for example cut&paste the query into a sql console and see what the result is.

Last, but not least you can try to generate some minimal test harness we ca use to reproduce the problem.

Good luck,
Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2008 3:54 pm 
Newbie

Joined: Fri Mar 10, 2006 8:52 pm
Posts: 5
The hibernate version is 3.2.0.ga
The hibenate annotations version is 3.2.0.GA
I am using oracle 8i


Below is the generated SQL from the hibernate trace:
Code:
select category0_.ID as ID1264_, category0_.DEFININGORG as DEFINING2_1264_, category0_.VERSION as VERSION1264_,
category0_.FULLCATEGORYNAME as FULLCATE4_1264_, category0_.FULLCATEGORYPATHNAME as FULLCATE5_1264_,
category0_.DISPLAY_NAME as DISPLAY6_1264_, category0_.PARENTID as PARENTID1264_,
category0_.MODEL as MODEL1264_, category0_.NODETYPE as NODETYPE1264_, category0_.MANUFACTURER as MANUFAC10_1264_,
category0_.DETAILLEVEL as DETAILL11_1264_, category0_.MANUFACTURER_WARRANTY_INFO_ID as MANUFAC12_1264_,
category0_.TRIAGE_INFO_ID as TRIAGE13_1264_,
case when category0_.DEFININGORG  in ('VAC', 'AMTS') then 'PROVIDER'
    when category0_.DEFININGORG  = 'ST' then 'ST'
    else 'VENDOR'
end as clazz_
from CATEGORY category0_ where category0_.DEFININGORG= 'EBAY' and category0_.ID= '3326'  and category0_.VERSION= '65'


It works fine when I run it in TOAD. The resulting value for _clazz is "VENDOR". The issue is that hibernate seems to be converting the DiscrimintorValue to "VENDOR " which is the same length as the String "PROVIDER". Since "VENDOR" and "VENDOR " are not equal it then gets the WrongClassException.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 4:40 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

have you temporarily tried to upgrade to a newer version of Hibernate to see whether the problem disappears? I don't think the problem lies in annotations, but rather in core, but as said I cannot reproduce it on the trunk.

You can create a jira issue if you like, preferably with a test case.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.