java.sql.SQLException:ORA-00942:表或视图不存在(Intellij生成的文件)
我正在尝试使用JPA+Hibernate来设置我的Oracle数据库。我将Intellij连接到数据源,然后使用数据库模式生成持久性映射。但是,每次运行以下代码时,我都会得到一个 错误(java.sql.SQLException:ORA-00942:表或视图不存在): persistence.xml和persistence类如下所示:java.sql.SQLException:ORA-00942:表或视图不存在(Intellij生成的文件),java,oracle,hibernate,jpa,intellij-idea,Java,Oracle,Hibernate,Jpa,Intellij Idea,我正在尝试使用JPA+Hibernate来设置我的Oracle数据库。我将Intellij连接到数据源,然后使用数据库模式生成持久性映射。但是,每次运行以下代码时,我都会得到一个 错误(java.sql.SQLException:ORA-00942:表或视图不存在): persistence.xml和persistence类如下所示: public class AdministrationUser { private long administrationUserId; priv
public class AdministrationUser {
private long administrationUserId;
private String userName;
private String name;
private Timestamp createDate;
private String createBy;
private Timestamp modDate;
private String modBy;
@Id
@Column(name = "administrationUserId", nullable = false, insertable = true, updatable = true, precision = 0)
public long getAdministrationUserId() {
return administrationUserId;
}
public void setAdministrationUserId(long administrationUserId) {
this.administrationUserId = administrationUserId;
}
@Basic
@Column(name = "userName", nullable = true, insertable = true, updatable = true, length = 64)
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Basic
@Column(name = "name", nullable = true, insertable = true, updatable = true, length = 64)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Basic
@Column(name = "createDate", nullable = true, insertable = true, updatable = true)
public Timestamp getCreateDate() {
return createDate;
}
public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
}
@Basic
@Column(name = "createBy", nullable = true, insertable = true, updatable = true, length = 15)
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
@Basic
@Column(name = "modDate", nullable = true, insertable = true, updatable = true)
public Timestamp getModDate() {
return modDate;
}
public void setModDate(Timestamp modDate) {
this.modDate = modDate;
}
@Basic
@Column(name = "modBy", nullable = true, insertable = true, updatable = true, length = 15)
public String getModBy() {
return modBy;
}
public void setModBy(String modBy) {
this.modBy = modBy;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="NewPersistenceUnit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>edu.rit.its.coopEval.model.AdministrationUser</class>
<properties>
<property name="hibernate.connection.url" value=""/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.connection.username" value=""/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
公共类管理用户{
私有长管理用户ID;
私有字符串用户名;
私有字符串名称;
私有时间戳createDate;
私有字符串createBy;
私有时间戳modDate;
私有字符串modBy;
@身份证
@列(name=“administrationUserId”,nullable=false,insertable=true,Updateable=true,precision=0)
公共长getAdministrationUserId(){
返回administrationUserId;
}
public void setAdministrationUserId(长administrationUserId){
this.administrationUserId=administrationUserId;
}
@基本的
@列(name=“userName”,nullable=true,insertable=true,updateable=true,length=64)
公共字符串getUserName(){
返回用户名;
}
public void setUserName(字符串用户名){
this.userName=用户名;
}
@基本的
@列(name=“name”,nullable=true,insertable=true,updateable=true,length=64)
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
@基本的
@列(name=“createDate”,nullable=true,insertable=true,updateable=true)
公共时间戳getCreateDate(){
返回创建日期;
}
public void setCreateDate(时间戳createDate){
this.createDate=createDate;
}
@基本的
@列(name=“createBy”,nullable=true,insertable=true,updateable=true,length=15)
公共字符串getCreateBy(){
返回createBy;
}
公共void setCreateBy(字符串createBy){
this.createBy=createBy;
}
@基本的
@列(name=“modDate”,nullable=true,insertable=true,updateable=true)
公共时间戳getModDate(){
返回日期;
}
public void setModDate(时间戳modDate){
this.modDate=modDate;
}
@基本的
@列(name=“modBy”,nullable=true,insertable=true,updateable=true,length=15)
公共字符串getModBy(){
返回modBy;
}
公共void setModBy(字符串modBy){
this.modBy=modBy;
}
}
org.hibernate.ejb.HibernatePersistence
edu.rit.its.coopEval.model.Administration用户
我故意删除了url、密码和用户名,但在我的代码中它们是正确的,因为我使用了完全相同的url、用户名和密码连接到toad中的数据库并创建了表。我不知道问题出在哪里。您可以尝试添加:
<property name="javax.persistence.schema-generation.database.action" value="create"/>
给你的persistence单位。否则,我猜您需要向您的实体添加一个@Table(name=”“)
编辑:
在我做了更多的研究之后,Hibernate看起来像这样,您可能需要这样:
<property name="hibernate.hbm2ddl.auto">update</property>
更新
我不知道像您这样将其设置为属性是否有效。我假设数据库中的表也被称为“administration\u user”?是的,它被称为“administration\u user”,不幸的是,它尝试了所有这些建议,但没有结果
<property name="hibernate.hbm2ddl.auto">update</property>