From dev-return-12965-apmail-openjpa-dev-archive=openjpa.apache.org@openjpa.apache.org Tue Jul 28 18:32:50 2009 Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 9399 invoked from network); 28 Jul 2009 18:32:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Jul 2009 18:32:50 -0000 Received: (qmail 53188 invoked by uid 500); 28 Jul 2009 18:34:07 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 53105 invoked by uid 500); 28 Jul 2009 18:34:07 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 53075 invoked by uid 99); 28 Jul 2009 18:34:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Jul 2009 18:34:06 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists+1214986235816-210739@n2.nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Jul 2009 18:33:56 +0000 Received: from tervel.nabble.com ([192.168.236.150]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1MVrUW-0001WW-0Y for dev@openjpa.apache.org; Tue, 28 Jul 2009 11:33:36 -0700 Date: Tue, 28 Jul 2009 11:33:36 -0700 (PDT) From: Ravi P Palacherla To: dev@openjpa.apache.org Message-ID: <1248806016011-3345152.post@n2.nabble.com> In-Reply-To: <1248304563673-3306514.post@n2.nabble.com> References: <1248299002248-3306077.post@n2.nabble.com> <72c1350f0907221557w18d01469h3971e4ed10942d29@mail.gmail.com> <1248304563673-3306514.post@n2.nabble.com> Subject: Re: ClasscastException when ClassCrietria is not used. MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: ravi.palacherla@oracle.com X-Virus-Checked: Checked by ClamAV on apache.org Hi, Created a JIRA for this: https://issues.apache.org/jira/browse/OPENJPA-1200 Regards, Ravi. Ravi P Palacherla wrote: > > Hi Mike, > > Please download the testcase from : > http://n2.nabble.com/file/n3306514/openJPATestCase.zip openJPATestCase.zip > > The following changes are needed : > build.xml ( point to proper "basedir" and "" ) > persistence.xml ( jdbc configurations.) > > Regards, > Ravi. > > > > Michael Dick wrote: >> >> Hi Ravi, >> >> Could you upload the testcase you mentioned? This sounds like an >> interesting >> issue, not sure I have the full picture at the moment, but it might >> warrant >> a JIRA for further investigation. >> >> -mike >> >> On Wed, Jul 22, 2009 at 4:43 PM, rpalache >> wrote: >> >>> >>> Hi , >>> >>> Here is the cause of the issue: >>> >>> getSelectSubclasses() of ValueMappingImpl.java is checking for criteria. >>> >>> "return (_criteria) ? Select.SUBS_JOINABLE >>> : Select.SUBS_ANY_JOINABLE;" >>> >>> If criteria is selected then "Select.SUBS_JOINABLE" is returned which >>> will >>> generate a select statement that has subclass criteria ( in my E.g: >>> t0.ITEM_TYPE = ? ) >>> >>> If criteria is not selected then "Select.SUBS_ANY_JOINABLE" is returned >>> which will not generate the above condition. >>> >>> So the question is if we have to make Select.SUBS_JOINABLE the default >>> behavior. >>> >>> I think throwing class cast exception is bad and hence the default >>> behavior >>> need to be changed to Select.SUBS_JOINABLE. >>> >>> Thanks in advance, >>> Ravi. >>> >>> >>> rpalache wrote: >>> > >>> > Hi All, >>> > >>> > I have an openJPA application with following entities: >>> > >>> > "Item" Entity with SINGLE_TABLE inheritance strategy. >>> > DiscriminatorColumn on this ITEM_TYPE. >>> > >>> > "Book" and "Movie" entities extend "Item." >>> > >>> > "Artist" entity has 1-many relationship with "Book." >>> > >>> > The following results in classcastexception : >>> > Artist artist = em.find(Artist.class, "Herman Hess"); >>> > List books= artist.getBooks(); >>> > >>> > "artist.getBooks()" results in rows that contain both "Book" >>> and"Movie" >>> > hence I get the following classcast : >>> > Exception in thread "main" java.lang.ClassCastException: >>> > org.apache.openjpa.enhance.model$Movie$pcsubclass >>> > >>> > When I add @ElementClassCriteria to the Artist to Book relationship >>> then >>> > that resolves the issue. >>> > @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, >>> > mappedBy="artist") >>> > @org.apache.openjpa.persistence.jdbc.ElementClassCriteria >>> > public List books; >>> > >>> > The reason for this issue is : >>> > without @ElementClassCriteria the SQL generated is : >>> > SELECT t0.UID1, t0.ITEM_TYPE, t0.title, t0.PAGE_COUNT FROM ITEM t0 >>> WHERE >>> > t0.ARTIST = ? >>> > [params=(String) Herman Hess] >>> > >>> > With @ElementClassCriteria the SQL generated is : >>> > SELECT t0.UID1, t0.ITEM_TYPE, t0.title, t0.PAGE_COUNT FROM ITEM t0 >>> WHERE >>> > t0.ARTIST = ? AND t0.ITEM_TYPE = ? >>> > [params=(String) Herman Hess, (String) BOOK] >>> > >>> > My questions regarding this is as follows: >>> > >>> > 1) @ElementClassCriteria is an openJPA specific annotation. Can I have >>> a >>> > JPA specific solution for this problem ? >>> > >>> > >>> > 2) If I have a very big application(s) and lots of relations with the >>> > above described behavior. >>> > Then do I have to add it to each and every entity class that has >>> the >>> > relationship ? >>> > Is there any property that I can define in the persistence.xml >>> rather >>> > than in entities ? >>> > >>> > I have a simple testcase demonstrating the issue. >>> > I can upload it if needed. >>> > >>> > Regards, >>> > Ravi. >>> > >>> > >>> >>> -- >>> View this message in context: >>> http://n2.nabble.com/ClasscastException-when-ClassCrietria-is-not-used.-tp3290568p3306077.html >>> Sent from the OpenJPA Developers mailing list archive at Nabble.com. >>> >> >> > > -- View this message in context: http://n2.nabble.com/ClasscastException-when-ClassCrietria-is-not-used.-tp3290568p3345152.html Sent from the OpenJPA Developers mailing list archive at Nabble.com.