ResultTransformer with createSQLQuery forces no camelCase in entity fields

前端 未结 3 525
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-07 03:10

I have an sql query as follows:

List employees = getCurrentSession()
                    .createSQLQuery(
                            \"select\"
         


        
3条回答
  •  悲&欢浪女
    2021-02-07 03:40

    You can use addScalar(String columnAlias, Type type) to explicitly declare the column alias of your native SQL:

      getCurrentSession()
      .createSQLQuery( "select e.id as id,e.first_name as firstName,e.password as password from xxxxxx")
                    .addScalar("id",StandardBasicTypes.INTEGER )
                    .addScalar("firstName",StandardBasicTypes.STRING )
                    .addScalar("password",StandardBasicTypes.STRING )
                    .setResultTransformer(Transformers.aliasToBean(Employee.class))
                    .list();
    

提交回复
热议问题