I am trying to setup with JPA + Hibernate to work with my Oracle database. I connected Intellij to my datasource and then generated the persistence mapping using the database schema. However every time I run the following code I get an
error(java.sql.SQLException: ORA-00942: table or view does not exist):
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();
}
The persistence.xml and persistence class looks like this:
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>
I have intentionally removed the url and password and username but within my code they are correct because I have used the exact same url, username, and password to connect to the database in toad and create the tables. I have no idea what the issue is.