I created a new Dynamic Web Project with the JPA facet enabled. I only have one entity defined and when I am trying to persist this entity, I get: Object: is not a known Entity type.
PERSISTANCE UNIT
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="ezimax" transaction-type="RESOURCE_LOCAL">
<class>za.co.ezimax.entity.Profile</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/ezimax_backend"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="javax.persistence.jdbc.password" value="xxxxxxx"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="eclipselink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>
</persistence>
ENTITY
package za.co.ezimax.entity;
import java.time.LocalDate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity()
@Table(name = "profile")
public class Profile {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name="first_name", nullable = false, length = 80)
private String firstName;
@Column(name="last_name", nullable = false, length = 80)
private String lastName;
@Column(name="birth_date", nullable = false)
private LocalDate birthDate;
@Column(name="sex", nullable = false)
private int sex;
@Column(name="sex", nullable = false)
private String mobileMac;
@Column(name="sex", nullable = false, length = 12)
private String mobileNo;
@Column(name="birth_date", nullable = false)
private LocalDate registrationDate;
@Column(name="user_password", nullable = false, length = 80)
private char[] userPassword;
public Profile() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public LocalDate getBirthDate() {
return birthDate;
}
public void setBirthDate(LocalDate birthDate) {
this.birthDate = birthDate;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public String getMobileMac() {
return mobileMac;
}
public void setMobileMac(String mobileMac) {
this.mobileMac = mobileMac;
}
public String getMobileNo() {
return mobileNo;
}
public void setMobileNo(String mobileNo) {
this.mobileNo = mobileNo;
}
public LocalDate getRegistrationDate() {
return registrationDate;
}
public void setRegistrationDate(LocalDate registrationDate) {
this.registrationDate = registrationDate;
}
public char[] getUserPassword() {
return userPassword;
}
public void setUserPassword(char[] userPassword) {
this.userPassword = userPassword;
}
}
PERSISTENCE CODE
EntityManagerFactory emf = Persistence.createEntityManagerFactory("ezimax");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
Profile profile = new Profile();
profile.setFirstName("Hendre");
profile.setLastName("Louw");
profile.setSex(1);
profile.setMobileMac("ff:ff:ff:ff:ff:ff:ff:ff");
profile.setMobileNo("+27832900001");
profile.setRegistrationDate(LocalDate.now());
profile.setUserPassword("password".toCharArray());
em.persist(profile);
em.getTransaction().commit();
em.close();
emf.close();
MAVEN
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.7.1</version>
</dependency>
I am running an running Eclipse 4.12.0. Please assist.