I am just dealing with JPA in a simple Java web application running on Glassfish 3 (the Persistence provider is EclipseLink). So far I really liked it (errors regarding netbeans / glassfish aside), but there is something that I want to be able to do this, I'm not sure how to do it.
I have an entity class (article) that is mapped to a database table (article). I am trying to make a query in a database that returns a computed column, but I cannot figure out how to set the property of the Article class so that the property is populated with the column value when the query is called.
If I make a regular request "select id, title, body from article", I get a list of article objects in order, with id, title and body properties filled. It works great.
However, if I do the following:
Query q = em.createNativeQuery("select id,title,shorttitle,datestamp,body,true as published, ts_headline(body,q,'ShortWord=0') as headline, type from articles,to_tsquery('english',?) as q where idxfti @@ q order by ts_rank(idxfti,q) desc",Article.class);
(this is a full-text search using tsearch2 in Postgres - this is a function specific to db, so I use NativeQuery)
You can see that I am getting a calculated column called a header. How to add a title property to the Article class so that it is populated with this query?
So far, I have been trying to set it to @Transient, but that just ends up being zero.