Native SQL « POJO « JPA Q&A

1. How can mapped result from SQL native query to java POJO class (no entity)

I have simple java pojo and it's no entity.

class MyClass {
    // fields, getter, setter and etc...
Also I have DAO with some function for execute native SQL query ...

2. Unmapped POJO used as class type in a native query's result exception

Given a class:

class MyClass {
    private String a;
    private String b;
    private String c;
and code like so:
Query q = getEntityManager()

3. creating POJO every time I have to use native sql ?

Hi all I wonder if I use with a native sql inside, I have to specify a specific POJO for retrivining all the columns or It's enough getting the list and after that acting as with HQL. I do not want create a POJO every time I have to use native sql inside an hbm mapping file. Exists any alternative? ...

4. How to make a native sql query that return pojos?

Caused by: org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.ErrorCodeConverter.convert( at org.hibernate.exception.JDBCExceptionHelper.convert( at org.hibernate.loader.Loader.doList( at org.hibernate.loader.Loader.list( at org.hibernate.loader.custom.CustomLoader.list( at org.hibernate.impl.SessionImpl.listCustomQuery( at org.hibernate.impl.SQLQueryImpl.list( at be.rmi.shark.hibernate.persistence.PersistenceManager.nativeList( ... 41 more Caused by: java.sql.SQLException: Nom de colonne non valide ...

5. Native SQL: How to annotate POJOs correctly?

@Entity @Table (name="TESTTABLE") public class Test implements Serializable{ private Integer fooBar; private String barFoo; private String fax; @Id @Column(name="FOOBAR") public Integer getFooBar() { return fooBar; } public void setFooBar(Integer fooBar) { ...