Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] MappedSuperclass NamedQueries

First, you can put @NamedQueries in whatever entity you want, there's
no rule that says they have to be declared in the entity they return.

Now the problem, let me see if I can line this up:

You have something like WidgetInvoice that has a MappedSuperclass of
AbstractInvoice.

In AbstractInvoice you declare a named query:

@NamedQuery(
    name="findInvoiceByName"
    query="Select i from AbstractInvoice i where i.name = :name")

Well, EclipseLink can't figure out what _table_ to map this back to,
it needs to turn that JPQL into SQL somehow -- so how would it know
that you really need to select out of WidgetInvoice and not maybe some
other entity like SprocketInvoice?

I think the idea of using a super class for entities that share
columns makes sense, however defining named queries based on that
abstract invoice doesn't make sense for the reason outlined above.

To solve your particular problem I would probably just solve it in a
custom DAO class.

For example, something like:

InvoiceDAO
{
EntityManager em;

List<T> TfindInvoicesByName(String name, Class<T> entityClazz)
{
 //build your query here based on which class -- perhaps using a NativeQuery?
 ...
...
return (List<T>)query.getResultSet();l
}
}


Make sense? Then again, maybe i'm missing your problem all together :)

./tch



On Wed, Feb 25, 2009 at 7:57 PM, Stephiems <stephanie@xxxxxxxxxxxxxx> wrote:
>
> Hi everyone. Thanks ahead of time for any help.
>
> I have an application that has multiple levels of inheritance, and I've run
> into an issue I can't seem to fix. I've got an abstract class PayableItem
> that is an Entity. It has the inheritance type of JOINED and a discriminator
> column and value. I then have an abstract class AbstractInvoice that is a
> MappedSuperclass. Then the idea is to have the possibility that there could
> be one or more classes that inherit the AbstractInvoice class that are
> Entities.
>
> Now, where the problem comes in, because the AbstractInvoice has important
> fields that I wish to have queries on, I have the NamedQueries on the
> AbstractInvoice class. I get an error about the AbstractInvoice class being
> an Unknown abstract schema type even though I've put it in the
> persistence.xml. I'm sure it is because the named queries in the FROM area
> reference AbstractInvoice instead of the class inheriting AbstractInvoice,
> and since AbstractInvoice is not an Entity, I can't seem to use it in the
> NamedQuery. The thing is, NamedQueries are allowed in MappedSuperclass
> classes, but that seems to be useless.
>
> Can anyone either clear up what I might be doing wrong, or if the above
> isn't really possible, or maybe suggest a better way of organizing things so
> that it will actually work?
>
> Thank you,
> Stephanie
> --
> View this message in context: http://www.nabble.com/MappedSuperclass-NamedQueries-tp22215521p22215521.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>


Back to the top