在线等待 Spring + Hiberate 表不存在问题?
配置文件 applicationContext.xml:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@192.168.0.165:1521:oradb" />
<property name="username" value="idinfo" />
<property name="password" value="idinfo" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource"><ref bean="dataSource" /></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.tseal.persistence.Seal</value>
</list>
</property>
</bean>
实体类 Seal :
@Table(name = "tb_seal", catalog = "etseal")
public class Seal
{
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name="id",length=40)
public Integer getId()
{
return this.id;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "createDate", nullable = false, length = 19)
public Date getCreateDate()
{
return this.createDate;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "updateDate", nullable = false, length = 19)
public Date getUpdateDate()
{
return this.updateDate;
}
@Column(name = "imgName", nullable = false, length = 75)
public String getImgName()
{
return this.imgName;
}
@Column(name = "thumbnail", nullable = false, length = 75)
public String getThumbnail()
{
return this.thumbnail;
}
@Column(name = "createUser", length = 20)
public String getCreateUser()
{
return this.createUser;
}
@Column(name = "updateUser", length = 20)
public String getUpdateUser()
{
return this.updateUser;
}
@Column(name = "sealName", nullable = false, length = 75)
public String getSealName()
{
return this.sealName;
}
@Column(name = "activesStatus", length = 1)
public String getActivesStatus()
{
return this.activesStatus;
}
@Column(name = "isRemote", length = 1)
public String getIsRemote()
{
return this.isRemote;
}
@Column(name = "width", length = 5)
public String getWidth()
{
return this.width;
}
@Column(name = "height", length = 5)
public String getHeight()
{
return this.height;
}
}
DAO 类:
String queryString= "select count(*) from Seal seal where seal.activesStatus = 1 order by seal.updateDate desc";
List list =
getHibernateTemplate().find(queryString);
执行 getHibernateTemplate().find(queryString) 时报:
Caused by:
org.hibernate.exception.SQLGrammarException:
could not execute queryCaused by:
java.sql.SQLException: ORA-00942: table or view does not exist
这个错误。
请问这可能是什么问题?
------解决方案--------------------不能执行查询 是不是数据库中的某一个数据不规范啊 我用mysql出现过这样的问题 不过oracle没用过 不会是配置文件的问题 配置文件出错不会报这的 配置文件和实体类应该没事 你用的是tomcat吗? 如果用的是tomcat建议配置一下打印日志的文件 看看执行到那错了