users@glassfish.java.net

Inharitance, Constructor Expressions in the SELECT Clause

From: <glassfish_at_javadesktop.org>
Date: Mon, 12 Feb 2007 12:22:37 PST

Hi!

When I tried to read a list of DTO (EmployeeDTO) and
I used inheritance and Constructor Expressions, it did not work;
I tried it on glassfish v2 build 25 and build 35.
I think, it is bug.

Please see my testing code:
[b]1. class entity.AbstractPerson[/b]

public abstract class AbstractPerson implements Serializable{
    @Id()
    private int id;
    @ManyToOne()
    private Country country; // Country entity is not displayed

    public AbstractPerson(){}
...

[b]2. class enity.Employee[/b]

public class Employee extends AbstractPerson{
    @ManyToOne()
    private JobPosition position; // JobPosition entity is not displayed
    private String note;

    public Employee(){}
...

[b]3. class dto.EmployeeDTO[/b]

public class EmployeeDTO implements Serializable{
    private int id;
    private Country country;
    private JobPosition position;
    private String note;

    public EmployeeDTO(int id, Country country, String note) {
        setId(id);
        setCountry(country);
        setNote(note);
    }

    public EmployeeDTO(int id, Country country, String note, JobPosition position) {
        this(id,country, note);
        setPosition(position);
    }
...

[b]4. Metod findAllEmployeesDoesNotWord in class dao.TestDAO[/b]

public List<EmployeeDTO> findAllEmployeesDoesNotWord(){
  Query query=em.createQuery("SELECT new dto.EmployeeDTO(res.id,res.country,res.note,res.position) FROM Employee res");
  return query.getResultList();
}

It throws Exception:

Caused by: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 9.1 (Build b25)): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 't1.job_position_id' in 'on clause'Error Code: 1054
Call:SELECT t0.id, t2.id, t2.iso_code, t1.NOTE, t3.id, t3.job_position FROM test_abstract_person t0 LEFT OUTER JOIN test_country t2 ON (t2.id = t0.country_id) LEFT OUTER JOIN test_job_position t3 ON (t3.id = t1.job_position_id), test_employee_adr t1 WHERE ((t1.id = t0.id) AND (t0.dtype = ?)) ORDER BY t0.id ASC

[b]5. Attantion: If I do not use inner entity JobPosition, it works![/b]

public List<EmployeeDTO> findAllEmployees(){
  Query query=em.createQuery("SELECT new dto.EmployeeDTO(res.id,res.country,res.note) FROM Employee res");
  return query.getResultList();
}

I can send you source code with Junit tests.

Fafi
[Message sent by forum member 'fafi' (fafi)]

http://forums.java.net/jive/thread.jspa?messageID=203506