开发者

hibernate query result to a predefined object?

开发者 https://www.devze.com 2023-03-06 14:23 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消