String sql = "SELECT BLAH_ID as id, FOO_DETAIL as detailText FROM blah";
Query query =
session.createSQLQuery(sql)
.addScalar("id")
.addScalar("detailText", new TextType())
.setResultTransformer(Transformers.aliasToBean(SomePojo.class));
class SomePojo {
private Long id;
private String detailText;
...getters and setters...
}
Now the real question is why did they do this native hibernate inside a Spring JpaRepository and not use NamedParameterJDBCTemplate with BeanPropertyRowMapper? It's very similar but I find the Spring style cleaner. Time to refactor.
title
fire chief's random developer tidbits
Thursday, November 29, 2012
Hibernate SQLQuery and Oracle CLOB (long text)
This is possibly very obvious but it took me a while to find the answer. Using existing native queries (SQLQuery) in hibernate I have a CLOB column I needed to map using a result set transformer. Note when you use one addScalar() you must map every column with addScalar() that you want returned. Use the org.hibernate.type.TextType (hibernate 3.5, it looks like hibernate 4 would be TextType.TEXTTYPE).
Monday, November 19, 2012
Grizzly slashes
Glassfish uses Grizzly internally to serve up web apps and grizzly by default doesn't allow encoded slashes in URLs, returning a 400 error. Here's how to change that setting:
http://java.net/jira/browse/JERSEY-1456
asadmin set
configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.encoded-slash-enabled=true
This came up when receiving an encrypted URL encoded string in as a path parameter to a restful JAX-RS service in Spring MVC.http://java.net/jira/browse/JERSEY-1456
Subscribe to:
Posts (Atom)