java - Spring 与 Hibernate 映射到数据库 View

标签 java hibernate spring-mvc spring-data

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

<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 Plugin 生成的

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 中映射 View 是相同的还是我遗漏了一些东西?

最佳答案

好的,我终于解决了这个问题。在 Oracle 数据库中,所有 View 名称都区分大小写,这意味着它全部位于双引号“ViewLoginPage”之间,因此经过少量搜索后我发现 this一切都像一个魅力,只需在反引号“ViewLoginPage”中的映射中设置列名称即可。

关于java - Spring 与 Hibernate 映射到数据库 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22729791/

相关文章:

java - 限制ip地址访问web服务

java - 保存多对多实体时出现问题

java - Spring 3MVC : @ModelAttribute method + @Autowired not working

java - 简单的 Servlet 映射

java - Feign 无法连接到本地主机

java - 为什么添加final方法修饰符会降低代码效率?

java - UiBinder 中的 gwt 按钮

java - hibernate.hbm2ddl.auto 自动不添加新列

java - Hibernate:外键的列数错误

java - 将 Elasticsearch 与 Spring MVC 集成