Spring与Hibernate映射到数据库视图

时间:2014-03-29 10:23:50

标签: java hibernate spring-mvc spring-data

我在web应用程序中使用带有spring的hibernate并且我必须从数据库视图(Oracle)获取数据我已经创建了映射并在spring中完成了数据库配置但是当我调用hibernateTemplate.find("From ViewLoginPage")时我得到了空列表但视图包含数据,视图中没有主键字段 我的映射是:

<class name="com.portal.ejb.ViewLoginPage" table="ViewLoginPage" schema="FENDEV">
        <composite-id name="id" class="com.portal.ejb.ViewLoginPageId">
            <key-property name="cid" type="big_decimal">
                <column name="cId" precision="22" scale="0" />
            </key-property>
            <key-property name="ctype" type="string">
                <column name="cType" length="50" />
            </key-property>
            <key-property name="ctag" type="string">
                <column name="cTag" length="50" />
            </key-property>
            <key-property name="ctagAttr" type="string">
                <column name="cTagAttr" length="50" />
            </key-property>
            <key-property name="cvalue" type="string">
                <column name="cValue" length="300" />
            </key-property>
            <key-property name="cparent" type="big_decimal">
                <column name="cParent" precision="22" scale="0" />
            </key-property>
            <key-property name="cdisplayOrder" type="big_decimal">
                <column name="cDisplayOrder" precision="22" scale="0" />
            </key-property>
        </composite-id>
    </class>

和pojo类是从Hibernate Code Generator插件生成的

public class ViewLoginPage implements java.io.Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private ViewLoginPageId id;

    public ViewLoginPage() {
    }

    public ViewLoginPage(ViewLoginPageId id) {
        this.id = id;
    }

    public ViewLoginPageId getId() {
        return this.id;
    }

    public void setId(ViewLoginPageId id) {
        this.id = id;
    }

}

public class ViewLoginPageId implements java.io.Serializable {

    private BigDecimal cid;
    private String ctype;
    private String ctag;
    private String ctagAttr;
    private String cvalue;
    private BigDecimal cparent;
    private BigDecimal cdisplayOrder;

    public ViewLoginPageId() {
    }

    public ViewLoginPageId(BigDecimal cid, String ctag, BigDecimal cdisplayOrder) {
        this.cid = cid;
        this.ctag = ctag;
        this.cdisplayOrder = cdisplayOrder;
    }

    public ViewLoginPageId(BigDecimal cid, String ctype, String ctag, String ctagAttr, String cvalue, BigDecimal cparent, BigDecimal cdisplayOrder) {
        this.cid = cid;
        this.ctype = ctype;
        this.ctag = ctag;
        this.ctagAttr = ctagAttr;
        this.cvalue = cvalue;
        this.cparent = cparent;
        this.cdisplayOrder = cdisplayOrder;
    }

    public BigDecimal getCid() {
        return this.cid;
    }

    public void setCid(BigDecimal cid) {
        this.cid = cid;
    }

    public String getCtype() {
        return this.ctype;
    }

    public void setCtype(String ctype) {
        this.ctype = ctype;
    }

    public String getCtag() {
        return this.ctag;
    }

    public void setCtag(String ctag) {
        this.ctag = ctag;
    }

    public String getCtagAttr() {
        return this.ctagAttr;
    }

    public void setCtagAttr(String ctagAttr) {
        this.ctagAttr = ctagAttr;
    }

    public String getCvalue() {
        return this.cvalue;
    }

    public void setCvalue(String cvalue) {
        this.cvalue = cvalue;
    }

    public BigDecimal getCparent() {
        return this.cparent;
    }

    public void setCparent(BigDecimal cparent) {
        this.cparent = cparent;
    }

    public BigDecimal getCdisplayOrder() {
        return this.cdisplayOrder;
    }

    public void setCdisplayOrder(BigDecimal cdisplayOrder) {
        this.cdisplayOrder = cdisplayOrder;
    }

    public boolean equals(Object other) {
        if ((this == other))
            return true;
        if ((other == null))
            return false;
        if (!(other instanceof ViewLoginPageId))
            return false;
        ViewLoginPageId castOther = (ViewLoginPageId) other;

        return ((this.getCid() == castOther.getCid()) || (this.getCid() != null && castOther.getCid() != null && this.getCid().equals(
                castOther.getCid())))
                && ((this.getCtype() == castOther.getCtype()) || (this.getCtype() != null && castOther.getCtype() != null && this.getCtype().equals(
                        castOther.getCtype())))
                && ((this.getCtag() == castOther.getCtag()) || (this.getCtag() != null && castOther.getCtag() != null && this.getCtag().equals(
                        castOther.getCtag())))
                && ((this.getCtagAttr() == castOther.getCtagAttr()) || (this.getCtagAttr() != null && castOther.getCtagAttr() != null && this
                        .getCtagAttr().equals(castOther.getCtagAttr())))
                && ((this.getCvalue() == castOther.getCvalue()) || (this.getCvalue() != null && castOther.getCvalue() != null && this.getCvalue()
                        .equals(castOther.getCvalue())))
                && ((this.getCparent() == castOther.getCparent()) || (this.getCparent() != null && castOther.getCparent() != null && this
                        .getCparent().equals(castOther.getCparent())))
                && ((this.getCdisplayOrder() == castOther.getCdisplayOrder()) || (this.getCdisplayOrder() != null
                        && castOther.getCdisplayOrder() != null && this.getCdisplayOrder().equals(castOther.getCdisplayOrder())));
    }

    public int hashCode() {
        int result = 17;

        result = 37 * result + (getCid() == null ? 0 : this.getCid().hashCode());
        result = 37 * result + (getCtype() == null ? 0 : this.getCtype().hashCode());
        result = 37 * result + (getCtag() == null ? 0 : this.getCtag().hashCode());
        result = 37 * result + (getCtagAttr() == null ? 0 : this.getCtagAttr().hashCode());
        result = 37 * result + (getCvalue() == null ? 0 : this.getCvalue().hashCode());
        result = 37 * result + (getCparent() == null ? 0 : this.getCparent().hashCode());
        result = 37 * result + (getCdisplayOrder() == null ? 0 : this.getCdisplayOrder().hashCode());
        return result;
    }

}

任何人都可以告诉我这个程序对于hibernate中的映射视图是否相同,或者我遗漏了什么?

1 个答案:

答案 0 :(得分:0)

好的,所以我终于解决了问题。在Oracle数据库中,所有视图名称都是区分大小写,这意味着它在双引号和#34; ViewLoginPage&#34;之间。所以在做了一点点搜索之后我找到this并且一切都像魅力一样只需在反引号中设置列名称&#34; ViewLoginPage&#34;。