java.sql.SQLException: ORA-00942: 表或视图不存在(Intellij 生成的文件)
Posted
技术标签:
【中文标题】java.sql.SQLException: ORA-00942: 表或视图不存在(Intellij 生成的文件)【英文标题】:java.sql.SQLException: ORA-00942: table or view does not exist (Intellij generated files) 【发布时间】:2015-01-29 20:28:23 【问题描述】:我正在尝试使用 JPA + Hibernate 进行设置以使用我的 Oracle 数据库。我将 Intellij 连接到我的数据源,然后使用数据库模式生成持久性映射。但是,每次我运行以下代码时,我都会得到一个
错误(java.sql.SQLException: ORA-00942: 表或视图不存在):
public static void main(String[] args)
System.out.println("Maven + Hibernate + Oracle");
PersistenceProvider persistenceProvider = new HibernatePersistence();
EntityManagerFactory entityManagerFactory = persistenceProvider.createEntityManagerFactory(
"NewPersistenceUnit",new HashMap());
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
AdministrationUser user = new AdministrationUser();
user.setUserName("mjh");
user.setName("Brendan");
user.setCreateDate(Timestamp.valueOf("2007-09-23 10:10:10.0"));
user.setCreateBy("Brendan");
user.setModDate(Timestamp.valueOf("2007-09-23 10:10:10.0"));
user.setModBy("Brendan");
entityManager.persist(user);
entityManager.getTransaction().commit();
persistence.xml 和持久化类如下所示:
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>
我故意删除了 url、密码和用户名,但在我的代码中它们是正确的,因为我使用完全相同的 url、用户名和密码连接到 toad 中的数据库并创建表。我不知道问题是什么。
【问题讨论】:
我假设您在数据库中的表也称为“administration_user”? 是的,它叫做“AdministrationUser” 【参考方案1】:您可以尝试添加:
<property name="javax.persistence.schema-generation.database.action" value="create"/>
到您的持久性单位。否则,我的猜测是您需要向您的实体添加 @Table(name = "<whatever its called>")
。
编辑:
经过我的更多研究,它看起来像 Hibernate,你可能需要这个:
<property name="hibernate.hbm2ddl.auto">update</property>
我不知道是否将其设置为像您所做的那样的属性。
【讨论】:
不幸地尝试了所有这些建议但没有结果以上是关于java.sql.SQLException: ORA-00942: 表或视图不存在(Intellij 生成的文件)的主要内容,如果未能解决你的问题,请参考以下文章