You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by David Ezzio <de...@bea.com> on 2007/06/23 04:08:46 UTC

How to query on interface in OpenJPA

Hi everyone,

I've recently run into a bug in Kodo JDO that appears to be occurring in 
OpenJPA. I have a test case that fails in Kodo JDO, but I'm stumped how 
to port the test case to OpenJPA.

My test case has two data classes and one interface that each class 
implements. SensorData and PublicData are the data classes and IData is 
the interface. The interface and classes are very simple.

What I need to do is query on the interface, and I don't know how to do 
it.  I don't know how to annotate the interface or whether I should.  I 
don't know how to write the query.  A simple, "select i from IData i" 
would be just fine if it worked.

Any suggestions?

Thanks,

David Ezzio


Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

Re: How to query on interface in OpenJPA

Posted by Jason Hanna <ja...@gmail.com>.
Hi David,

I'm certainly no expert on the subject - I've only been working with
OpenJPA for a few weeks. I don't think what you're trying to do
directly translates, however.

Someone on the list please correct me if I'm wrong, but I don't think
it's possible to annotate an interface.

If I understand what you've described, it sounds like you have two
distinct classes that are likely quite similar, and need to implement
the methods outlined in your IData interface.

It appears that you want to execute a single query that would return
results for both types of classes.

I believe the details of how you achieve this also depend on your
relational design, but I'm doing something similar for a utility
billing project using inheritance.

I've got an annotated base class, Bill, containing all the common
attributes of my different bill types. I have several other annotated
classes (e.g. ElectricBill, WaterBill) that extend Bill but also have
their own unique attributes.

I was starting from a clean slate, so I had the luxury of setting up
my relational tables in any way I chose, I don't know if that's the
case for your project/example.

In short, my relational design consists of a common base table (Bill)
and related tables containing unique data for each different bill type
(ElectricBill, WaterBill). This allows me to query my data with the
type of flexibility you describe in your post.

I believe there is another mapping approach that allows your data to
be stored in a single table (InheritanceType.SINGLE_TABLE), but I
haven't tried it yet.

Section 2.12.6 of the OpenJPA documentation has a pretty good
description of the metadata mapping strategies available when you're
dealing with inheritance.

Hope this helps. Please let me know if I'm way off base or have missed
something. I'd been managing teams for several years and still don't
have my coding legs completely back yet.

Regards,
-jmh

Jason M. Hanna
President & Founder
Coincident, Inc.
http://coincident.com

On 6/22/07, David Ezzio <de...@bea.com> wrote:
> Hi everyone,
>
> I've recently run into a bug in Kodo JDO that appears to be occurring in
> OpenJPA. I have a test case that fails in Kodo JDO, but I'm stumped how
> to port the test case to OpenJPA.
>
> My test case has two data classes and one interface that each class
> implements. SensorData and PublicData are the data classes and IData is
> the interface. The interface and classes are very simple.
>
> What I need to do is query on the interface, and I don't know how to do
> it.  I don't know how to annotate the interface or whether I should.  I
> don't know how to write the query.  A simple, "select i from IData i"
> would be just fine if it worked.
>
> Any suggestions?
>
> Thanks,
>
> David Ezzio
>
>
> Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.
>

Re: How to query on interface in OpenJPA

Posted by Patrick Linskey <pl...@gmail.com>.
OpenJPA certainly should be able to handle interfaces -- see
OpenJPAEntityManager.createInstance(). I don't see any tests of this
method in the OpenJPA test suite, though.

-Patrick

On 6/23/07, Marc Prud'hommeaux <mp...@apache.org> wrote:
> David-
>
> According to the spec, "interfaces should not be designated as
> entities", and if you can't declare it as an entity, then you don't
> have anywhere to specify its interface name.
>
> The Kodo JDO layer on top of OpenJPA does support querying on
> interfaces, though. I wonder if it would work if you did "select i
> from com.somepackage.IData i". If that raises an error, can you post
> the stack trace?
>
>
> On Jun 22, 2007, at 7:08 PM, David Ezzio wrote:
>
> > Hi everyone,
> >
> > I've recently run into a bug in Kodo JDO that appears to be
> > occurring in
> > OpenJPA. I have a test case that fails in Kodo JDO, but I'm stumped
> > how
> > to port the test case to OpenJPA.
> >
> > My test case has two data classes and one interface that each class
> > implements. SensorData and PublicData are the data classes and
> > IData is
> > the interface. The interface and classes are very simple.
> >
> > What I need to do is query on the interface, and I don't know how
> > to do
> > it.  I don't know how to annotate the interface or whether I
> > should.  I
> > don't know how to write the query.  A simple, "select i from IData i"
> > would be just fine if it worked.
> >
> > Any suggestions?
> >
> > Thanks,
> >
> > David Ezzio
> >
> >
> > Notice:  This email message, together with any attachments, may
> > contain information  of  BEA Systems,  Inc.,  its subsidiaries
> > and  affiliated entities,  that may be confidential,  proprietary,
> > copyrighted  and/or legally privileged, and is intended solely for
> > the use of the individual or entity named in this message. If you
> > are not the intended recipient, and have received this message in
> > error, please immediately return this by email and then delete it.
>
>


-- 
Patrick Linskey
202 669 5907

Re: How to query on interface in OpenJPA

Posted by David Ezzio <de...@bea.com>.
Hi Patrick,

I'm not using the "newInstance" method.

Objects are created using their constuctors.

My problem is selecting or deleting the objects through the interface.

My original bug is in Kodo JDO which supports using interfaces in this 
manner but has a bug in the order of loading metadata.  I'm trying to 
port the test case over to OpenJPA because it looks to me that the bug 
that Kodo is encountering is in OpenJPA.  I thought if I could port the 
failing test case, then we could make a determination whether it was a 
bug in OpenJPA or not, and how best to fix it.  My first attempt to fix 
it in OpenJPA was a resounding disaster.

My worry is that we have behavior in OpenJPA that OpenJPA does not use 
and cannot test.  That's why, I think, it is worthwhile trying to run 
this down.

David


Patrick Linskey wrote:
> Certainly there is either a bug in the fact that we don't implement it
> or a bug in the fact that our javadocs claim that we do.
> 
> It sounds like we should probably beef up our test cases for the
> EM.newInstance() method and / or change the javadocs for that method
> to reflect reality.
> 
> -Patrick
> 
> On 7/9/07, Marc Prud'hommeaux <mp...@apache.org> wrote:
>>
>> I guess we just don't support it in JPA, then. It might be a good
>> future enhancement, though, and probably not that difficult to
>> implement (since it is already supported in a derivative product of
>> OpenJPA).
>>
>>
>>
>> On Jul 9, 2007, at 10:32 AM, David Ezzio (asmtp) wrote:
>>
>> > Hi Marc,
>> >
>> > I took your suggestion and got an error when using the interface
>> > whether for a select or delete query.  The error is "No metadata
>> > was found for type "interface problem.model.IData". The class is
>> > not enhanced."
>> >
>> > I did include the interface in the list of classes in
>> > persistence.xml without any complain during enhancement or mapping-
>> > validation.  The mappingtool creates two tables, one for SensorData
>> > and one for PublicData.
>> >
>> > I've attached a zip of the text file with the testing code and
>> > stack trace.
>> >
>> > Any insights welcomed.
>> >
>> > Thanks,
>> >
>> > David
>> >
>> > Marc Prud'hommeaux wrote:
>> >> David-
>> >> According to the spec, "interfaces should not be designated as
>> >> entities", and if you can't declare it as an entity, then you
>> >> don't have anywhere to specify its interface name.
>> >> The Kodo JDO layer on top of OpenJPA does support querying on
>> >> interfaces, though. I wonder if it would work if you did "select i
>> >> from com.somepackage.IData i". If that raises an error, can you
>> >> post the stack trace?
>> >> On Jun 22, 2007, at 7:08 PM, David Ezzio wrote:
>> >>> Hi everyone,
>> >>>
>> >>> I've recently run into a bug in Kodo JDO that appears to be
>> >>> occurring in
>> >>> OpenJPA. I have a test case that fails in Kodo JDO, but I'm
>> >>> stumped how
>> >>> to port the test case to OpenJPA.
>> >>>
>> >>> My test case has two data classes and one interface that each class
>> >>> implements. SensorData and PublicData are the data classes and
>> >>> IData is
>> >>> the interface. The interface and classes are very simple.
>> >>>
>> >>> What I need to do is query on the interface, and I don't know how
>> >>> to do
>> >>> it.  I don't know how to annotate the interface or whether I
>> >>> should.  I
>> >>> don't know how to write the query.  A simple, "select i from
>> >>> IData i"
>> >>> would be just fine if it worked.
>> >>>
>> >>> Any suggestions?
>> >>>
>> >>> Thanks,
>> >>>
>> >>> David Ezzio
>> >>>
>> >>>
>> >>> Notice:  This email message, together with any attachments, may
>> >>> contain information  of  BEA Systems,  Inc.,  its subsidiaries
>> >>> and  affiliated entities,  that may be confidential,
>> >>> proprietary,  copyrighted  and/or legally privileged, and is
>> >>> intended solely for the use of the individual or entity named in
>> >>> this message. If you are not the intended recipient, and have
>> >>> received this message in error, please immediately return this by
>> >>> email and then delete it.
>> >>> <OpenJPAInterfaceBugOutput.zip>
>>
>>
> 
> 


Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

Re: How to query on interface in OpenJPA

Posted by Patrick Linskey <pl...@gmail.com>.
Certainly there is either a bug in the fact that we don't implement it
or a bug in the fact that our javadocs claim that we do.

It sounds like we should probably beef up our test cases for the
EM.newInstance() method and / or change the javadocs for that method
to reflect reality.

-Patrick

On 7/9/07, Marc Prud'hommeaux <mp...@apache.org> wrote:
>
> I guess we just don't support it in JPA, then. It might be a good
> future enhancement, though, and probably not that difficult to
> implement (since it is already supported in a derivative product of
> OpenJPA).
>
>
>
> On Jul 9, 2007, at 10:32 AM, David Ezzio (asmtp) wrote:
>
> > Hi Marc,
> >
> > I took your suggestion and got an error when using the interface
> > whether for a select or delete query.  The error is "No metadata
> > was found for type "interface problem.model.IData". The class is
> > not enhanced."
> >
> > I did include the interface in the list of classes in
> > persistence.xml without any complain during enhancement or mapping-
> > validation.  The mappingtool creates two tables, one for SensorData
> > and one for PublicData.
> >
> > I've attached a zip of the text file with the testing code and
> > stack trace.
> >
> > Any insights welcomed.
> >
> > Thanks,
> >
> > David
> >
> > Marc Prud'hommeaux wrote:
> >> David-
> >> According to the spec, "interfaces should not be designated as
> >> entities", and if you can't declare it as an entity, then you
> >> don't have anywhere to specify its interface name.
> >> The Kodo JDO layer on top of OpenJPA does support querying on
> >> interfaces, though. I wonder if it would work if you did "select i
> >> from com.somepackage.IData i". If that raises an error, can you
> >> post the stack trace?
> >> On Jun 22, 2007, at 7:08 PM, David Ezzio wrote:
> >>> Hi everyone,
> >>>
> >>> I've recently run into a bug in Kodo JDO that appears to be
> >>> occurring in
> >>> OpenJPA. I have a test case that fails in Kodo JDO, but I'm
> >>> stumped how
> >>> to port the test case to OpenJPA.
> >>>
> >>> My test case has two data classes and one interface that each class
> >>> implements. SensorData and PublicData are the data classes and
> >>> IData is
> >>> the interface. The interface and classes are very simple.
> >>>
> >>> What I need to do is query on the interface, and I don't know how
> >>> to do
> >>> it.  I don't know how to annotate the interface or whether I
> >>> should.  I
> >>> don't know how to write the query.  A simple, "select i from
> >>> IData i"
> >>> would be just fine if it worked.
> >>>
> >>> Any suggestions?
> >>>
> >>> Thanks,
> >>>
> >>> David Ezzio
> >>>
> >>>
> >>> Notice:  This email message, together with any attachments, may
> >>> contain information  of  BEA Systems,  Inc.,  its subsidiaries
> >>> and  affiliated entities,  that may be confidential,
> >>> proprietary,  copyrighted  and/or legally privileged, and is
> >>> intended solely for the use of the individual or entity named in
> >>> this message. If you are not the intended recipient, and have
> >>> received this message in error, please immediately return this by
> >>> email and then delete it.
> >>> <OpenJPAInterfaceBugOutput.zip>
>
>


-- 
Patrick Linskey
202 669 5907

Re: How to query on interface in OpenJPA

Posted by Marc Prud'hommeaux <mp...@apache.org>.
I guess we just don't support it in JPA, then. It might be a good  
future enhancement, though, and probably not that difficult to  
implement (since it is already supported in a derivative product of  
OpenJPA).



On Jul 9, 2007, at 10:32 AM, David Ezzio (asmtp) wrote:

> Hi Marc,
>
> I took your suggestion and got an error when using the interface  
> whether for a select or delete query.  The error is "No metadata  
> was found for type "interface problem.model.IData". The class is  
> not enhanced."
>
> I did include the interface in the list of classes in  
> persistence.xml without any complain during enhancement or mapping- 
> validation.  The mappingtool creates two tables, one for SensorData  
> and one for PublicData.
>
> I've attached a zip of the text file with the testing code and  
> stack trace.
>
> Any insights welcomed.
>
> Thanks,
>
> David
>
> Marc Prud'hommeaux wrote:
>> David-
>> According to the spec, "interfaces should not be designated as  
>> entities", and if you can't declare it as an entity, then you  
>> don't have anywhere to specify its interface name.
>> The Kodo JDO layer on top of OpenJPA does support querying on  
>> interfaces, though. I wonder if it would work if you did "select i  
>> from com.somepackage.IData i". If that raises an error, can you  
>> post the stack trace?
>> On Jun 22, 2007, at 7:08 PM, David Ezzio wrote:
>>> Hi everyone,
>>>
>>> I've recently run into a bug in Kodo JDO that appears to be  
>>> occurring in
>>> OpenJPA. I have a test case that fails in Kodo JDO, but I'm  
>>> stumped how
>>> to port the test case to OpenJPA.
>>>
>>> My test case has two data classes and one interface that each class
>>> implements. SensorData and PublicData are the data classes and  
>>> IData is
>>> the interface. The interface and classes are very simple.
>>>
>>> What I need to do is query on the interface, and I don't know how  
>>> to do
>>> it.  I don't know how to annotate the interface or whether I  
>>> should.  I
>>> don't know how to write the query.  A simple, "select i from  
>>> IData i"
>>> would be just fine if it worked.
>>>
>>> Any suggestions?
>>>
>>> Thanks,
>>>
>>> David Ezzio
>>>
>>>
>>> Notice:  This email message, together with any attachments, may  
>>> contain information  of  BEA Systems,  Inc.,  its subsidiaries   
>>> and  affiliated entities,  that may be confidential,   
>>> proprietary,  copyrighted  and/or legally privileged, and is  
>>> intended solely for the use of the individual or entity named in  
>>> this message. If you are not the intended recipient, and have  
>>> received this message in error, please immediately return this by  
>>> email and then delete it.
>>> <OpenJPAInterfaceBugOutput.zip>


Re: How to query on interface in OpenJPA

Posted by "David Ezzio (asmtp)" <de...@bea.com>.
Hi Marc,

I took your suggestion and got an error when using the interface whether 
for a select or delete query.  The error is "No metadata was found for 
type "interface problem.model.IData". The class is not enhanced."

I did include the interface in the list of classes in persistence.xml 
without any complain during enhancement or mapping-validation.  The 
mappingtool creates two tables, one for SensorData and one for PublicData.

I've attached a zip of the text file with the testing code and stack trace.

Any insights welcomed.

Thanks,

David

Marc Prud'hommeaux wrote:
> David-
> 
> According to the spec, "interfaces should not be designated as 
> entities", and if you can't declare it as an entity, then you don't have 
> anywhere to specify its interface name.
> 
> The Kodo JDO layer on top of OpenJPA does support querying on 
> interfaces, though. I wonder if it would work if you did "select i from 
> com.somepackage.IData i". If that raises an error, can you post the 
> stack trace?
> 
> 
> On Jun 22, 2007, at 7:08 PM, David Ezzio wrote:
> 
>> Hi everyone,
>>
>> I've recently run into a bug in Kodo JDO that appears to be occurring in
>> OpenJPA. I have a test case that fails in Kodo JDO, but I'm stumped how
>> to port the test case to OpenJPA.
>>
>> My test case has two data classes and one interface that each class
>> implements. SensorData and PublicData are the data classes and IData is
>> the interface. The interface and classes are very simple.
>>
>> What I need to do is query on the interface, and I don't know how to do
>> it.  I don't know how to annotate the interface or whether I should.  I
>> don't know how to write the query.  A simple, "select i from IData i"
>> would be just fine if it worked.
>>
>> Any suggestions?
>>
>> Thanks,
>>
>> David Ezzio
>>
>>
>> Notice:  This email message, together with any attachments, may 
>> contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  
>> affiliated entities,  that may be confidential,  proprietary,  
>> copyrighted  and/or legally privileged, and is intended solely for the 
>> use of the individual or entity named in this message. If you are not 
>> the intended recipient, and have received this message in error, 
>> please immediately return this by email and then delete it.
> 
> 

Re: How to query on interface in OpenJPA

Posted by Marc Prud'hommeaux <mp...@apache.org>.
David-

According to the spec, "interfaces should not be designated as  
entities", and if you can't declare it as an entity, then you don't  
have anywhere to specify its interface name.

The Kodo JDO layer on top of OpenJPA does support querying on  
interfaces, though. I wonder if it would work if you did "select i  
from com.somepackage.IData i". If that raises an error, can you post  
the stack trace?


On Jun 22, 2007, at 7:08 PM, David Ezzio wrote:

> Hi everyone,
>
> I've recently run into a bug in Kodo JDO that appears to be  
> occurring in
> OpenJPA. I have a test case that fails in Kodo JDO, but I'm stumped  
> how
> to port the test case to OpenJPA.
>
> My test case has two data classes and one interface that each class
> implements. SensorData and PublicData are the data classes and  
> IData is
> the interface. The interface and classes are very simple.
>
> What I need to do is query on the interface, and I don't know how  
> to do
> it.  I don't know how to annotate the interface or whether I  
> should.  I
> don't know how to write the query.  A simple, "select i from IData i"
> would be just fine if it worked.
>
> Any suggestions?
>
> Thanks,
>
> David Ezzio
>
>
> Notice:  This email message, together with any attachments, may  
> contain information  of  BEA Systems,  Inc.,  its subsidiaries   
> and  affiliated entities,  that may be confidential,  proprietary,   
> copyrighted  and/or legally privileged, and is intended solely for  
> the use of the individual or entity named in this message. If you  
> are not the intended recipient, and have received this message in  
> error, please immediately return this by email and then delete it.