hibernate query result to a predefined object?
It is possible in hibernate to get a result of a query to a mapped db object.
Is it possible to create a non-persistent object and get the query result into this object?
for example
session.createSQLQuery(select a,b,c from table).list.addEntity(myclass.class)
if myclass is:
publi开发者_高级运维c class myclass{
private int a;
private int b;
private int c;
.
.
.
}
You can use AliasToBeanResultTransformer
:
session.createSQLQuery("select a,b,c from table")
.setResultTransformer(new AliasToBeanResultTransformer(myclass.class))
.list();
No, Hibernate will only work with classes that are mapped ahead of time.
精彩评论