Java Spring与Hibernate映射到数据库视图
我在web应用程序中使用hibernate和spring,我必须从数据库视图(Oracle)获取数据。我已经在spring中创建了映射并完成了数据库配置,但当我调用Java Spring与Hibernate映射到数据库视图,java,hibernate,spring-mvc,spring-data,Java,Hibernate,Spring Mvc,Spring Data,我在web应用程序中使用hibernate和spring,我必须从数据库视图(Oracle)获取数据。我已经在spring中创建了映射并完成了数据库配置,但当我调用hibernateTemplate.find(“从ViewLoginPage”)时我得到的是空列表,但视图包含数据,并且视图中没有主键字段 我的映射是: <class name="com.portal.ejb.ViewLoginPage" table="ViewLoginPage" schema="FENDEV">
hibernateTemplate.find(“从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>
有谁能告诉我,这个过程对hibernate中的视图映射是一样的,还是我遗漏了什么?好的,所以我终于解决了这个问题。在Oracle数据库中,所有视图名称都是区分大小写的,这意味着它在所有两个引号之间都是“ViewLoginPage”,因此在进行了少量搜索之后,我发现了所有内容,一切都像一个符咒,只需在反勾“
ViewLoginPage”中的映射中设置列名即可。问题是,直接来自Oracle的错误消息是什么,说明:ORA-00942:表或视图不存在
。Hibernate与此异常无关。@jbnize我知道,但该视图存在于数据库中,使用sql plus我也可以查询该视图并获取数据包,但我认为可能是映射中缺少了某些内容。您可能使用了不同的架构、不同的视图名称或不同的主机或数据库。我重复一遍:这是一个SQLException,由Oracle JDBC驱动程序引发。Hibernate与此无关。我在发布之前检查了两次question@JBNizet根据您的建议,我现在已经检查了所有内容。我得到的一件事是,在查询视图时,视图名称之间有空格,因此我将其删除,但现在列表中没有数据。
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;
}
}