获取一个没有在Hibernate中映射的bean类型列表 [英] Get a list of bean type without being mapped in Hibernate

查看:103
本文介绍了获取一个没有在Hibernate中映射的bean类型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我可以得到一个bean类型列表(它还没有被映射) Hibernate的getSession()?



我试图做的是从查询中获取两个值。这些值来自不同的表格。我已经完成了我的查询,但是当我尝试执行getSession时,它说我的类没有被映射。
我不映射它,因为没有要映射的表。我创建了一个名为ObjetivoAdapter的类,其中包含两个字符串(我需要放入列表中的信息)。
我也创建了这个类,因为我需要一个我的信息列表。



这些是我得到信息的表格:



表:producto。
栏目:描述。
栏目:codigo_barras



表格:objetivo。
列:codigo_barras_objetivo(FK与表producto的codigo_barras)。
列:promocion_id(FK带有来自表promocion的id)

表:promocion
列:id

这是我的类bean ObjetivoAdapter:

  public class ObjetivoAdapter {

private String nombreProducto;
私人字符串codigoBarrasObjetivo;

public void ObjetivoAdapter(String nombreProducto,String codigoBarrasObjetivo){
this.nombreProducto = nombreProducto;
this.codigoBarrasObjetivo = codigoBarrasObjetivo;
}

public String getCodigoBarrasObjetivo(){
return codigoBarrasObjetivo;
}

public void setCodigoBarrasObjetivo(String codigoBarrasObjetivo){
this.codigoBarrasObjetivo = codigoBarrasObjetivo;
}

public String getNombreProducto(){
return nombreProducto;
}

public void setNombreProducto(String nombreProducto){
this.nombreProducto = nombreProducto;
}

}

这是我的查询:

  public List< ObjetivoAdapter> getInfo(String codBarras){
String sql =SELECT o.codigo_barras_objetivo,p.descripcion_corta FROM objetivo o
+INNER JOIN product o o o.codigo_barras_objetivo = p.codigo_barras
+ INNER JOIN promocion pr ON o.promocion_id = pr.id
+WHERE codigo_barras ='+ codBarras +';;
列表< ObjetivoAdapter> listaOA = getSession()。createSQLQuery(sql).addEntity(ObjetivoAdapter.class).list();
return listaOA;
}

任何帮助将不胜感激。

使用 setResultTransformer(AliasToBeanResultTransformer)而不是 addEntity()和所有应该罚款


I don't know if this is even possible in hibernate.

Can I get a list of a bean type (which hasn't been mapped) with the getSession() of Hibernate?

What I'm trying to do is get two values from a query. Those values are from differents tables. I have done my query but when I try to execute the getSession, it says that my Class is not Mapped. I don't map it becasue there is no table to be mapped. I created a class named as ObjetivoAdapter which contains two Strings (The information i need to put into a list). Also I created the class because I need a list of my information.

Those are the tables from which I get the information:

Table: producto. Column: descripcion. Column: codigo_barras

Table: objetivo. Column: codigo_barras_objetivo (FK with codigo_barras from table producto). Column: promocion_id (FK with id from table promocion)

Table: promocion Column: id

This is my class bean ObjetivoAdapter:

public class ObjetivoAdapter {

    private String nombreProducto;
    private String codigoBarrasObjetivo;

    public void ObjetivoAdapter(String nombreProducto, String codigoBarrasObjetivo) {
        this.nombreProducto = nombreProducto;
        this.codigoBarrasObjetivo = codigoBarrasObjetivo;
    }

    public String getCodigoBarrasObjetivo() {
        return codigoBarrasObjetivo;
    }

    public void setCodigoBarrasObjetivo(String codigoBarrasObjetivo) {
        this.codigoBarrasObjetivo = codigoBarrasObjetivo;
    }

    public String getNombreProducto() {
        return nombreProducto;
    }

    public void setNombreProducto(String nombreProducto) {
        this.nombreProducto = nombreProducto;
    }

}

And this is my query:

public List<ObjetivoAdapter> getInfo(String codBarras) {
        String sql = "SELECT o.codigo_barras_objetivo, p.descripcion_corta FROM objetivo o "
                + "INNER JOIN producto p ON o.codigo_barras_objetivo = p.codigo_barras "
                + "INNER JOIN promocion pr ON o.promocion_id = pr.id "
                + "WHERE codigo_barras = ' " + codBarras + "';";
        List<ObjetivoAdapter> listaOA = getSession().createSQLQuery(sql).addEntity(ObjetivoAdapter.class).list();
        return listaOA;
    }

Any help will be appreciated.

解决方案

Use a setResultTransformer(AliasToBeanResultTransformer) instead of addEntity() and all should be fine

这篇关于获取一个没有在Hibernate中映射的bean类型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆