Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Get specific entries from a Table using the "InheritanceType.SINGLE_TABLE-strategy" by using the DiscriminatorValue

Tom is correct, but in your example you would want either:
  "Select p from Person p where TYPE(p) = Employee"
Or you can just select the Employee subclass:
  "Select e from Employee e"
Both queries will return Employees, but the second will also return Employee subclasses if there are any.

JPQL is object based and dtype is not an attribute in the java object, which is why it cannot be used within the query.

Best Regards,
Chris

On 11/01/2012 9:03 AM, Tom Ware wrote:
JPQL provides a TYPE operator.

Here is an example from the spec:

SELECT e
FROM Employee e
WHERE TYPE(e) IN (Exempt, Contractor)


On 11/01/2012 8:56 AM, Rick van Son wrote:
Hello everyone,

I've a class Person and a class Employee.
Employee is extended from the class Person.
Person has its own Table, using "InheritanceType.SINGLE_TABLE" as
Inheritance
strategy.
Employee entries are thus also stored in the table of Person.

However, I couldn't find the magic SELECT query for EclipseLink to get
only the
Employee-entries from the table Person.

PostgreSQL finds "SELECT person.* FROM Person person WHERE person.dtype =
'Employee';" very delicious and gives me the right results. But
EclipseLink is
less nice and doesn't want to see the DiscriminatorColumn "dtype" when
I do
"List<Employee> employees = (List<Employee>) em.createQuery("SELECT
OBJECT(Employee) FROM Person person WHERE person.dtype =
'Employee';").getResultList();".

Trying to cast 'Employee' to CHARACTER VARYING(31) in various ways
didn't also work.

Does anyone have a suggestion to solve this?

Thanks in advance,

Rick


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top