happening “ java.lang.ExceptionInInitializerError ” Caused by “ Unable to build EntityManagerFactory...











up vote
0
down vote

favorite












I want create a web application and use JPA for model layer in MVC for the first time . But I'm having trouble.
The program shows me this error :



Nov 11, 2018 10:56:49 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Nov 11, 2018 10:56:49 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.0.Final}
Nov 11, 2018 10:56:49 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
Nov 11, 2018 10:56:49 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist

Exception in thread "main" java.lang.ExceptionInInitializerError
at model.bl.PersonManager.main(PersonManager.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: MyConnection] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:930)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:72)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at util.JPAProvider.<clinit>(JPAProvider.java:13)
... 6 more

Caused by: org.hibernate.MappingException: Unable to find column with logical name: UID in org.hibernate.mapping.Table(USERS) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:552)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:257)
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1331)
at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:791)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:719)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:668)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1593)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1350)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920)
... 11 more


Person class :



package model.entity;
import model.bl.PersonManager;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

//mapping class to table
@Entity (name = "person")
@Table(name = "USERS")
@EntityListeners(value = PersonManager.class)

public class Person implements Serializable
{

@Id // create id and fill auto by sequence in database
@Column(name="UID" ,columnDefinition = "NUMBER" )
@SequenceGenerator(name = "mySeq" , sequenceName = "DB_MYSEQ")
@GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq")
private long uId;


@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
private List<Pictures> picturesList;


@Basic
@Column (name = "USERNAME" , columnDefinition = "NVARCHAR2(30)" , nullable = false , unique = true)
private String username ;

@Basic
@Column (name = "USER_PASSWORD" , columnDefinition = "NVARCHAR2(32)" , nullable = false , unique = true)
private String password ;

@Basic
@Column (name = "EMAIL" , columnDefinition = "NVARCHAR2(40)" , nullable = false)
private String email;


@Basic
@Column (name = "SEX" , columnDefinition = "NVARCHAR2(20)")
private String sex ;

//--------------------------------------------------------

public Person() { }

public Person(String username, String password, String email, String sex, String userPic) {
this.username = username;
this.password = password;
this.email = email;
this.sex = sex;
this.userPic = userPic;
}
public Person(String username, String password, String email ,String sex, String userPic,List<Pictures> picturesList ) {
this.picturesList = picturesList;
this.sex = sex;
this.userPic = userPic;
this.email = email;
this.password = password;
this.username = username;
}

//--------------------------------------------------------

public void setUsername(String username) {
this.username = username;
}

public void setPassword(String password) {
this.password = password;
}

public void setEmail(String email) {
this.email = email;
}

public void setUserPic(String userPic) {
this.userPic = userPic;
}

public void setSex(String sex) {
this.sex = sex;
}

public void setuId(long uId) {this.uId = uId;}

//--------------------------------------------------------

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public String getUserPic() {
return userPic;
}

public String getEmail() {
return email;
}

public String getSex() {
return sex;
}

public long getuId() {return uId;}

}
}


Pictures class :



package model.entity;

import javax.persistence.*;
import java.io.Serializable;

@Entity(name = "picture")
@Table(name = "PICTURE")

public class Pictures implements Serializable
{
@Id // create id and fill auto by sequence in database
@Column(name="PID" ,columnDefinition = "NUMBER" )
@SequenceGenerator(name = "mySeq2" , sequenceName = "DB_MYSEQ2")
@GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq2")
private long pId;


@Basic
@Column (name = "PICADRESS" , columnDefinition = "NVARCHAR2(50)" , nullable = false)
private String picAdress ;

@Basic
@Column (name = "CAPTION" , columnDefinition = "LONG")
private String caption;

@Basic // user picture for profile
@Column (name = "LIKES" , columnDefinition = "NUMBER")
private int likes;

//--------------------------------------------------------
public Pictures(){}

public Pictures( String picAdress, String caption, int likes) {
this.picAdress = picAdress;
this.caption = caption;
this.likes = likes;
}
//--------------------------------------------------------

public void setPid(long pid) {
this.pId = pid;
}

public void setLikes(int likes) {
this.likes = likes;
}

public void setPicAdress(String picAdress) {
this.picAdress = picAdress;
}

public void setCaption(String caption) {
this.caption = caption;
}

//--------------------------------------------------------

public int getLikes() {
return likes;
}

public String getCaption() {
return caption;
}

public String getPicAdress() {
return picAdress;
}

public long getPid() {
return pId;
}
}


my JPA Provider is :



public class JPAProvider {

private static final EntityManagerFactory entityManagerFactory;//instate of session for connect to database
static{
entityManagerFactory = Persistence.createEntityManagerFactory("MyConnection");
}

public static EntityManagerFactory getEntityManagerFactory() {
return entityManagerFactory;
}
}


PersonManager class is :



public class PersonManager {

public static void main(String args) {

EntityManager entityManager = JPAProvider.getEntityManagerFactory().createEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();

Person person = new Person("midas" , "midas123" , "aaaaa@gmail.com", "female" ,"female-user.png" );
Pictures pictures = new Pictures("aaa" , "akflkkglhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" ,2);
Pictures pictures2 = new Pictures("nnbnbn" , "affddAlllllllllllllllllllllllllllllllllllll" ,5);
List<Pictures> picturesList =new ArrayList<Pictures>();
picturesList.add(pictures);
picturesList.add(pictures2);
person.setPicturesList(picturesList);

entityManager.persist(person);
entityTransaction.commit();
entityManager.close();
}
}


and persistence.xml :



<persistence-unit name="MyConnection" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
<property name="hibernate.connection.username" value="midas"/>
<property name="hibernate.connection.password" value="midas123"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="show_sql" value="true"></property>
<property name="hibernate.globally_quoted_identifiers" value="true"/>
</properties>
</persistence-unit>


I used the following libraries :



1)hibernate-enverc-4.2.0.final



2)hibernate-jpa-2.0-api-1.0.1-final.jar



3)tomcat library



my JDK version = 1.8.0-172



my IDE = IntellyJ Idea



I use Oracle 11g .



I tried to solve the problem by solving similar questions, but I could not .
for example I checked the following topics that were more similar to my problem :



[Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed



[Getting Exception in thread "main" java.lang.ExceptionInInitializerError Exception



Additional explanation: No tables have been created in the database so far.










share|improve this question
























  • Is the schema already created on the database?
    – Michael Wiles
    Nov 10 at 11:06










  • @MichaelWiles No ، Not made.
    – farzane
    Nov 10 at 11:25












  • In passing, I think you should not build the EntityManagerFactory in a static initializer. Its initialization is very susceptible to fail, so putting it here guarantees that you cannot deal with its failing should it happen. The initialization belongs some place else.
    – Arthur Noseda
    Nov 10 at 11:36










  • @ArthurNoseda I tested the same program in the same way and it runs correctly. Of course, that program was just a training example for the JPA.
    – farzane
    Nov 10 at 11:47










  • looks like column UID is not present can you change hm2ddl property to <property name="hibernate.hbm2ddl.auto" value="create"/> and try
    – Nawnit Sen
    Nov 10 at 11:55















up vote
0
down vote

favorite












I want create a web application and use JPA for model layer in MVC for the first time . But I'm having trouble.
The program shows me this error :



Nov 11, 2018 10:56:49 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Nov 11, 2018 10:56:49 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.0.Final}
Nov 11, 2018 10:56:49 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
Nov 11, 2018 10:56:49 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist

Exception in thread "main" java.lang.ExceptionInInitializerError
at model.bl.PersonManager.main(PersonManager.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: MyConnection] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:930)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:72)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at util.JPAProvider.<clinit>(JPAProvider.java:13)
... 6 more

Caused by: org.hibernate.MappingException: Unable to find column with logical name: UID in org.hibernate.mapping.Table(USERS) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:552)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:257)
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1331)
at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:791)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:719)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:668)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1593)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1350)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920)
... 11 more


Person class :



package model.entity;
import model.bl.PersonManager;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

//mapping class to table
@Entity (name = "person")
@Table(name = "USERS")
@EntityListeners(value = PersonManager.class)

public class Person implements Serializable
{

@Id // create id and fill auto by sequence in database
@Column(name="UID" ,columnDefinition = "NUMBER" )
@SequenceGenerator(name = "mySeq" , sequenceName = "DB_MYSEQ")
@GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq")
private long uId;


@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
private List<Pictures> picturesList;


@Basic
@Column (name = "USERNAME" , columnDefinition = "NVARCHAR2(30)" , nullable = false , unique = true)
private String username ;

@Basic
@Column (name = "USER_PASSWORD" , columnDefinition = "NVARCHAR2(32)" , nullable = false , unique = true)
private String password ;

@Basic
@Column (name = "EMAIL" , columnDefinition = "NVARCHAR2(40)" , nullable = false)
private String email;


@Basic
@Column (name = "SEX" , columnDefinition = "NVARCHAR2(20)")
private String sex ;

//--------------------------------------------------------

public Person() { }

public Person(String username, String password, String email, String sex, String userPic) {
this.username = username;
this.password = password;
this.email = email;
this.sex = sex;
this.userPic = userPic;
}
public Person(String username, String password, String email ,String sex, String userPic,List<Pictures> picturesList ) {
this.picturesList = picturesList;
this.sex = sex;
this.userPic = userPic;
this.email = email;
this.password = password;
this.username = username;
}

//--------------------------------------------------------

public void setUsername(String username) {
this.username = username;
}

public void setPassword(String password) {
this.password = password;
}

public void setEmail(String email) {
this.email = email;
}

public void setUserPic(String userPic) {
this.userPic = userPic;
}

public void setSex(String sex) {
this.sex = sex;
}

public void setuId(long uId) {this.uId = uId;}

//--------------------------------------------------------

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public String getUserPic() {
return userPic;
}

public String getEmail() {
return email;
}

public String getSex() {
return sex;
}

public long getuId() {return uId;}

}
}


Pictures class :



package model.entity;

import javax.persistence.*;
import java.io.Serializable;

@Entity(name = "picture")
@Table(name = "PICTURE")

public class Pictures implements Serializable
{
@Id // create id and fill auto by sequence in database
@Column(name="PID" ,columnDefinition = "NUMBER" )
@SequenceGenerator(name = "mySeq2" , sequenceName = "DB_MYSEQ2")
@GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq2")
private long pId;


@Basic
@Column (name = "PICADRESS" , columnDefinition = "NVARCHAR2(50)" , nullable = false)
private String picAdress ;

@Basic
@Column (name = "CAPTION" , columnDefinition = "LONG")
private String caption;

@Basic // user picture for profile
@Column (name = "LIKES" , columnDefinition = "NUMBER")
private int likes;

//--------------------------------------------------------
public Pictures(){}

public Pictures( String picAdress, String caption, int likes) {
this.picAdress = picAdress;
this.caption = caption;
this.likes = likes;
}
//--------------------------------------------------------

public void setPid(long pid) {
this.pId = pid;
}

public void setLikes(int likes) {
this.likes = likes;
}

public void setPicAdress(String picAdress) {
this.picAdress = picAdress;
}

public void setCaption(String caption) {
this.caption = caption;
}

//--------------------------------------------------------

public int getLikes() {
return likes;
}

public String getCaption() {
return caption;
}

public String getPicAdress() {
return picAdress;
}

public long getPid() {
return pId;
}
}


my JPA Provider is :



public class JPAProvider {

private static final EntityManagerFactory entityManagerFactory;//instate of session for connect to database
static{
entityManagerFactory = Persistence.createEntityManagerFactory("MyConnection");
}

public static EntityManagerFactory getEntityManagerFactory() {
return entityManagerFactory;
}
}


PersonManager class is :



public class PersonManager {

public static void main(String args) {

EntityManager entityManager = JPAProvider.getEntityManagerFactory().createEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();

Person person = new Person("midas" , "midas123" , "aaaaa@gmail.com", "female" ,"female-user.png" );
Pictures pictures = new Pictures("aaa" , "akflkkglhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" ,2);
Pictures pictures2 = new Pictures("nnbnbn" , "affddAlllllllllllllllllllllllllllllllllllll" ,5);
List<Pictures> picturesList =new ArrayList<Pictures>();
picturesList.add(pictures);
picturesList.add(pictures2);
person.setPicturesList(picturesList);

entityManager.persist(person);
entityTransaction.commit();
entityManager.close();
}
}


and persistence.xml :



<persistence-unit name="MyConnection" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
<property name="hibernate.connection.username" value="midas"/>
<property name="hibernate.connection.password" value="midas123"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="show_sql" value="true"></property>
<property name="hibernate.globally_quoted_identifiers" value="true"/>
</properties>
</persistence-unit>


I used the following libraries :



1)hibernate-enverc-4.2.0.final



2)hibernate-jpa-2.0-api-1.0.1-final.jar



3)tomcat library



my JDK version = 1.8.0-172



my IDE = IntellyJ Idea



I use Oracle 11g .



I tried to solve the problem by solving similar questions, but I could not .
for example I checked the following topics that were more similar to my problem :



[Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed



[Getting Exception in thread "main" java.lang.ExceptionInInitializerError Exception



Additional explanation: No tables have been created in the database so far.










share|improve this question
























  • Is the schema already created on the database?
    – Michael Wiles
    Nov 10 at 11:06










  • @MichaelWiles No ، Not made.
    – farzane
    Nov 10 at 11:25












  • In passing, I think you should not build the EntityManagerFactory in a static initializer. Its initialization is very susceptible to fail, so putting it here guarantees that you cannot deal with its failing should it happen. The initialization belongs some place else.
    – Arthur Noseda
    Nov 10 at 11:36










  • @ArthurNoseda I tested the same program in the same way and it runs correctly. Of course, that program was just a training example for the JPA.
    – farzane
    Nov 10 at 11:47










  • looks like column UID is not present can you change hm2ddl property to <property name="hibernate.hbm2ddl.auto" value="create"/> and try
    – Nawnit Sen
    Nov 10 at 11:55













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want create a web application and use JPA for model layer in MVC for the first time . But I'm having trouble.
The program shows me this error :



Nov 11, 2018 10:56:49 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Nov 11, 2018 10:56:49 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.0.Final}
Nov 11, 2018 10:56:49 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
Nov 11, 2018 10:56:49 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist

Exception in thread "main" java.lang.ExceptionInInitializerError
at model.bl.PersonManager.main(PersonManager.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: MyConnection] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:930)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:72)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at util.JPAProvider.<clinit>(JPAProvider.java:13)
... 6 more

Caused by: org.hibernate.MappingException: Unable to find column with logical name: UID in org.hibernate.mapping.Table(USERS) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:552)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:257)
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1331)
at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:791)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:719)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:668)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1593)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1350)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920)
... 11 more


Person class :



package model.entity;
import model.bl.PersonManager;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

//mapping class to table
@Entity (name = "person")
@Table(name = "USERS")
@EntityListeners(value = PersonManager.class)

public class Person implements Serializable
{

@Id // create id and fill auto by sequence in database
@Column(name="UID" ,columnDefinition = "NUMBER" )
@SequenceGenerator(name = "mySeq" , sequenceName = "DB_MYSEQ")
@GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq")
private long uId;


@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
private List<Pictures> picturesList;


@Basic
@Column (name = "USERNAME" , columnDefinition = "NVARCHAR2(30)" , nullable = false , unique = true)
private String username ;

@Basic
@Column (name = "USER_PASSWORD" , columnDefinition = "NVARCHAR2(32)" , nullable = false , unique = true)
private String password ;

@Basic
@Column (name = "EMAIL" , columnDefinition = "NVARCHAR2(40)" , nullable = false)
private String email;


@Basic
@Column (name = "SEX" , columnDefinition = "NVARCHAR2(20)")
private String sex ;

//--------------------------------------------------------

public Person() { }

public Person(String username, String password, String email, String sex, String userPic) {
this.username = username;
this.password = password;
this.email = email;
this.sex = sex;
this.userPic = userPic;
}
public Person(String username, String password, String email ,String sex, String userPic,List<Pictures> picturesList ) {
this.picturesList = picturesList;
this.sex = sex;
this.userPic = userPic;
this.email = email;
this.password = password;
this.username = username;
}

//--------------------------------------------------------

public void setUsername(String username) {
this.username = username;
}

public void setPassword(String password) {
this.password = password;
}

public void setEmail(String email) {
this.email = email;
}

public void setUserPic(String userPic) {
this.userPic = userPic;
}

public void setSex(String sex) {
this.sex = sex;
}

public void setuId(long uId) {this.uId = uId;}

//--------------------------------------------------------

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public String getUserPic() {
return userPic;
}

public String getEmail() {
return email;
}

public String getSex() {
return sex;
}

public long getuId() {return uId;}

}
}


Pictures class :



package model.entity;

import javax.persistence.*;
import java.io.Serializable;

@Entity(name = "picture")
@Table(name = "PICTURE")

public class Pictures implements Serializable
{
@Id // create id and fill auto by sequence in database
@Column(name="PID" ,columnDefinition = "NUMBER" )
@SequenceGenerator(name = "mySeq2" , sequenceName = "DB_MYSEQ2")
@GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq2")
private long pId;


@Basic
@Column (name = "PICADRESS" , columnDefinition = "NVARCHAR2(50)" , nullable = false)
private String picAdress ;

@Basic
@Column (name = "CAPTION" , columnDefinition = "LONG")
private String caption;

@Basic // user picture for profile
@Column (name = "LIKES" , columnDefinition = "NUMBER")
private int likes;

//--------------------------------------------------------
public Pictures(){}

public Pictures( String picAdress, String caption, int likes) {
this.picAdress = picAdress;
this.caption = caption;
this.likes = likes;
}
//--------------------------------------------------------

public void setPid(long pid) {
this.pId = pid;
}

public void setLikes(int likes) {
this.likes = likes;
}

public void setPicAdress(String picAdress) {
this.picAdress = picAdress;
}

public void setCaption(String caption) {
this.caption = caption;
}

//--------------------------------------------------------

public int getLikes() {
return likes;
}

public String getCaption() {
return caption;
}

public String getPicAdress() {
return picAdress;
}

public long getPid() {
return pId;
}
}


my JPA Provider is :



public class JPAProvider {

private static final EntityManagerFactory entityManagerFactory;//instate of session for connect to database
static{
entityManagerFactory = Persistence.createEntityManagerFactory("MyConnection");
}

public static EntityManagerFactory getEntityManagerFactory() {
return entityManagerFactory;
}
}


PersonManager class is :



public class PersonManager {

public static void main(String args) {

EntityManager entityManager = JPAProvider.getEntityManagerFactory().createEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();

Person person = new Person("midas" , "midas123" , "aaaaa@gmail.com", "female" ,"female-user.png" );
Pictures pictures = new Pictures("aaa" , "akflkkglhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" ,2);
Pictures pictures2 = new Pictures("nnbnbn" , "affddAlllllllllllllllllllllllllllllllllllll" ,5);
List<Pictures> picturesList =new ArrayList<Pictures>();
picturesList.add(pictures);
picturesList.add(pictures2);
person.setPicturesList(picturesList);

entityManager.persist(person);
entityTransaction.commit();
entityManager.close();
}
}


and persistence.xml :



<persistence-unit name="MyConnection" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
<property name="hibernate.connection.username" value="midas"/>
<property name="hibernate.connection.password" value="midas123"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="show_sql" value="true"></property>
<property name="hibernate.globally_quoted_identifiers" value="true"/>
</properties>
</persistence-unit>


I used the following libraries :



1)hibernate-enverc-4.2.0.final



2)hibernate-jpa-2.0-api-1.0.1-final.jar



3)tomcat library



my JDK version = 1.8.0-172



my IDE = IntellyJ Idea



I use Oracle 11g .



I tried to solve the problem by solving similar questions, but I could not .
for example I checked the following topics that were more similar to my problem :



[Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed



[Getting Exception in thread "main" java.lang.ExceptionInInitializerError Exception



Additional explanation: No tables have been created in the database so far.










share|improve this question















I want create a web application and use JPA for model layer in MVC for the first time . But I'm having trouble.
The program shows me this error :



Nov 11, 2018 10:56:49 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Nov 11, 2018 10:56:49 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.0.Final}
Nov 11, 2018 10:56:49 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
Nov 11, 2018 10:56:49 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist

Exception in thread "main" java.lang.ExceptionInInitializerError
at model.bl.PersonManager.main(PersonManager.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: MyConnection] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:930)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:72)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at util.JPAProvider.<clinit>(JPAProvider.java:13)
... 6 more

Caused by: org.hibernate.MappingException: Unable to find column with logical name: UID in org.hibernate.mapping.Table(USERS) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:552)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:257)
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1331)
at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:791)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:719)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:668)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1593)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1350)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920)
... 11 more


Person class :



package model.entity;
import model.bl.PersonManager;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

//mapping class to table
@Entity (name = "person")
@Table(name = "USERS")
@EntityListeners(value = PersonManager.class)

public class Person implements Serializable
{

@Id // create id and fill auto by sequence in database
@Column(name="UID" ,columnDefinition = "NUMBER" )
@SequenceGenerator(name = "mySeq" , sequenceName = "DB_MYSEQ")
@GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq")
private long uId;


@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
private List<Pictures> picturesList;


@Basic
@Column (name = "USERNAME" , columnDefinition = "NVARCHAR2(30)" , nullable = false , unique = true)
private String username ;

@Basic
@Column (name = "USER_PASSWORD" , columnDefinition = "NVARCHAR2(32)" , nullable = false , unique = true)
private String password ;

@Basic
@Column (name = "EMAIL" , columnDefinition = "NVARCHAR2(40)" , nullable = false)
private String email;


@Basic
@Column (name = "SEX" , columnDefinition = "NVARCHAR2(20)")
private String sex ;

//--------------------------------------------------------

public Person() { }

public Person(String username, String password, String email, String sex, String userPic) {
this.username = username;
this.password = password;
this.email = email;
this.sex = sex;
this.userPic = userPic;
}
public Person(String username, String password, String email ,String sex, String userPic,List<Pictures> picturesList ) {
this.picturesList = picturesList;
this.sex = sex;
this.userPic = userPic;
this.email = email;
this.password = password;
this.username = username;
}

//--------------------------------------------------------

public void setUsername(String username) {
this.username = username;
}

public void setPassword(String password) {
this.password = password;
}

public void setEmail(String email) {
this.email = email;
}

public void setUserPic(String userPic) {
this.userPic = userPic;
}

public void setSex(String sex) {
this.sex = sex;
}

public void setuId(long uId) {this.uId = uId;}

//--------------------------------------------------------

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public String getUserPic() {
return userPic;
}

public String getEmail() {
return email;
}

public String getSex() {
return sex;
}

public long getuId() {return uId;}

}
}


Pictures class :



package model.entity;

import javax.persistence.*;
import java.io.Serializable;

@Entity(name = "picture")
@Table(name = "PICTURE")

public class Pictures implements Serializable
{
@Id // create id and fill auto by sequence in database
@Column(name="PID" ,columnDefinition = "NUMBER" )
@SequenceGenerator(name = "mySeq2" , sequenceName = "DB_MYSEQ2")
@GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq2")
private long pId;


@Basic
@Column (name = "PICADRESS" , columnDefinition = "NVARCHAR2(50)" , nullable = false)
private String picAdress ;

@Basic
@Column (name = "CAPTION" , columnDefinition = "LONG")
private String caption;

@Basic // user picture for profile
@Column (name = "LIKES" , columnDefinition = "NUMBER")
private int likes;

//--------------------------------------------------------
public Pictures(){}

public Pictures( String picAdress, String caption, int likes) {
this.picAdress = picAdress;
this.caption = caption;
this.likes = likes;
}
//--------------------------------------------------------

public void setPid(long pid) {
this.pId = pid;
}

public void setLikes(int likes) {
this.likes = likes;
}

public void setPicAdress(String picAdress) {
this.picAdress = picAdress;
}

public void setCaption(String caption) {
this.caption = caption;
}

//--------------------------------------------------------

public int getLikes() {
return likes;
}

public String getCaption() {
return caption;
}

public String getPicAdress() {
return picAdress;
}

public long getPid() {
return pId;
}
}


my JPA Provider is :



public class JPAProvider {

private static final EntityManagerFactory entityManagerFactory;//instate of session for connect to database
static{
entityManagerFactory = Persistence.createEntityManagerFactory("MyConnection");
}

public static EntityManagerFactory getEntityManagerFactory() {
return entityManagerFactory;
}
}


PersonManager class is :



public class PersonManager {

public static void main(String args) {

EntityManager entityManager = JPAProvider.getEntityManagerFactory().createEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();

Person person = new Person("midas" , "midas123" , "aaaaa@gmail.com", "female" ,"female-user.png" );
Pictures pictures = new Pictures("aaa" , "akflkkglhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" ,2);
Pictures pictures2 = new Pictures("nnbnbn" , "affddAlllllllllllllllllllllllllllllllllllll" ,5);
List<Pictures> picturesList =new ArrayList<Pictures>();
picturesList.add(pictures);
picturesList.add(pictures2);
person.setPicturesList(picturesList);

entityManager.persist(person);
entityTransaction.commit();
entityManager.close();
}
}


and persistence.xml :



<persistence-unit name="MyConnection" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
<property name="hibernate.connection.username" value="midas"/>
<property name="hibernate.connection.password" value="midas123"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="show_sql" value="true"></property>
<property name="hibernate.globally_quoted_identifiers" value="true"/>
</properties>
</persistence-unit>


I used the following libraries :



1)hibernate-enverc-4.2.0.final



2)hibernate-jpa-2.0-api-1.0.1-final.jar



3)tomcat library



my JDK version = 1.8.0-172



my IDE = IntellyJ Idea



I use Oracle 11g .



I tried to solve the problem by solving similar questions, but I could not .
for example I checked the following topics that were more similar to my problem :



[Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed



[Getting Exception in thread "main" java.lang.ExceptionInInitializerError Exception



Additional explanation: No tables have been created in the database so far.







java hibernate jpa model-view-controller






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 7:49

























asked Nov 10 at 9:03









farzane

54




54












  • Is the schema already created on the database?
    – Michael Wiles
    Nov 10 at 11:06










  • @MichaelWiles No ، Not made.
    – farzane
    Nov 10 at 11:25












  • In passing, I think you should not build the EntityManagerFactory in a static initializer. Its initialization is very susceptible to fail, so putting it here guarantees that you cannot deal with its failing should it happen. The initialization belongs some place else.
    – Arthur Noseda
    Nov 10 at 11:36










  • @ArthurNoseda I tested the same program in the same way and it runs correctly. Of course, that program was just a training example for the JPA.
    – farzane
    Nov 10 at 11:47










  • looks like column UID is not present can you change hm2ddl property to <property name="hibernate.hbm2ddl.auto" value="create"/> and try
    – Nawnit Sen
    Nov 10 at 11:55


















  • Is the schema already created on the database?
    – Michael Wiles
    Nov 10 at 11:06










  • @MichaelWiles No ، Not made.
    – farzane
    Nov 10 at 11:25












  • In passing, I think you should not build the EntityManagerFactory in a static initializer. Its initialization is very susceptible to fail, so putting it here guarantees that you cannot deal with its failing should it happen. The initialization belongs some place else.
    – Arthur Noseda
    Nov 10 at 11:36










  • @ArthurNoseda I tested the same program in the same way and it runs correctly. Of course, that program was just a training example for the JPA.
    – farzane
    Nov 10 at 11:47










  • looks like column UID is not present can you change hm2ddl property to <property name="hibernate.hbm2ddl.auto" value="create"/> and try
    – Nawnit Sen
    Nov 10 at 11:55
















Is the schema already created on the database?
– Michael Wiles
Nov 10 at 11:06




Is the schema already created on the database?
– Michael Wiles
Nov 10 at 11:06












@MichaelWiles No ، Not made.
– farzane
Nov 10 at 11:25






@MichaelWiles No ، Not made.
– farzane
Nov 10 at 11:25














In passing, I think you should not build the EntityManagerFactory in a static initializer. Its initialization is very susceptible to fail, so putting it here guarantees that you cannot deal with its failing should it happen. The initialization belongs some place else.
– Arthur Noseda
Nov 10 at 11:36




In passing, I think you should not build the EntityManagerFactory in a static initializer. Its initialization is very susceptible to fail, so putting it here guarantees that you cannot deal with its failing should it happen. The initialization belongs some place else.
– Arthur Noseda
Nov 10 at 11:36












@ArthurNoseda I tested the same program in the same way and it runs correctly. Of course, that program was just a training example for the JPA.
– farzane
Nov 10 at 11:47




@ArthurNoseda I tested the same program in the same way and it runs correctly. Of course, that program was just a training example for the JPA.
– farzane
Nov 10 at 11:47












looks like column UID is not present can you change hm2ddl property to <property name="hibernate.hbm2ddl.auto" value="create"/> and try
– Nawnit Sen
Nov 10 at 11:55




looks like column UID is not present can you change hm2ddl property to <property name="hibernate.hbm2ddl.auto" value="create"/> and try
– Nawnit Sen
Nov 10 at 11:55












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Looks like problem is with @JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
referencedColumnName attribute points to the related column in asociated/referenced entity, i.e. column name of the primary key. By default it is primary key of associated entity. You are not required to fill the referencedColumnName if the referenced entity has single column as PK, because there is no doubt what column it references (i.e. primary key column of associated entity).
change that line to @JoinColumn(name = "FK_PERSON") it should work.



For more info about referencedColumnName refer to "What is referencedColumnName used for in JPA?"






share|improve this answer





















  • Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
    – farzane
    Nov 11 at 10:38












  • if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
    – Nawnit Sen
    Nov 11 at 10:40










  • javax.persistence.RollbackException: Error while committing the transaction--->Caused by:javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
    – farzane
    Nov 11 at 10:52












  • it says table doesnt exist...just check in the db if that particular table exist or not
    – Nawnit Sen
    Nov 11 at 10:55






  • 1




    I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
    – farzane
    Nov 11 at 12:12











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237463%2fhappening-java-lang-exceptionininitializererror-caused-by-unable-to-build%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










Looks like problem is with @JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
referencedColumnName attribute points to the related column in asociated/referenced entity, i.e. column name of the primary key. By default it is primary key of associated entity. You are not required to fill the referencedColumnName if the referenced entity has single column as PK, because there is no doubt what column it references (i.e. primary key column of associated entity).
change that line to @JoinColumn(name = "FK_PERSON") it should work.



For more info about referencedColumnName refer to "What is referencedColumnName used for in JPA?"






share|improve this answer





















  • Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
    – farzane
    Nov 11 at 10:38












  • if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
    – Nawnit Sen
    Nov 11 at 10:40










  • javax.persistence.RollbackException: Error while committing the transaction--->Caused by:javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
    – farzane
    Nov 11 at 10:52












  • it says table doesnt exist...just check in the db if that particular table exist or not
    – Nawnit Sen
    Nov 11 at 10:55






  • 1




    I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
    – farzane
    Nov 11 at 12:12















up vote
0
down vote



accepted










Looks like problem is with @JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
referencedColumnName attribute points to the related column in asociated/referenced entity, i.e. column name of the primary key. By default it is primary key of associated entity. You are not required to fill the referencedColumnName if the referenced entity has single column as PK, because there is no doubt what column it references (i.e. primary key column of associated entity).
change that line to @JoinColumn(name = "FK_PERSON") it should work.



For more info about referencedColumnName refer to "What is referencedColumnName used for in JPA?"






share|improve this answer





















  • Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
    – farzane
    Nov 11 at 10:38












  • if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
    – Nawnit Sen
    Nov 11 at 10:40










  • javax.persistence.RollbackException: Error while committing the transaction--->Caused by:javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
    – farzane
    Nov 11 at 10:52












  • it says table doesnt exist...just check in the db if that particular table exist or not
    – Nawnit Sen
    Nov 11 at 10:55






  • 1




    I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
    – farzane
    Nov 11 at 12:12













up vote
0
down vote



accepted







up vote
0
down vote



accepted






Looks like problem is with @JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
referencedColumnName attribute points to the related column in asociated/referenced entity, i.e. column name of the primary key. By default it is primary key of associated entity. You are not required to fill the referencedColumnName if the referenced entity has single column as PK, because there is no doubt what column it references (i.e. primary key column of associated entity).
change that line to @JoinColumn(name = "FK_PERSON") it should work.



For more info about referencedColumnName refer to "What is referencedColumnName used for in JPA?"






share|improve this answer












Looks like problem is with @JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
referencedColumnName attribute points to the related column in asociated/referenced entity, i.e. column name of the primary key. By default it is primary key of associated entity. You are not required to fill the referencedColumnName if the referenced entity has single column as PK, because there is no doubt what column it references (i.e. primary key column of associated entity).
change that line to @JoinColumn(name = "FK_PERSON") it should work.



For more info about referencedColumnName refer to "What is referencedColumnName used for in JPA?"







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 9:58









Nawnit Sen

33037




33037












  • Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
    – farzane
    Nov 11 at 10:38












  • if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
    – Nawnit Sen
    Nov 11 at 10:40










  • javax.persistence.RollbackException: Error while committing the transaction--->Caused by:javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
    – farzane
    Nov 11 at 10:52












  • it says table doesnt exist...just check in the db if that particular table exist or not
    – Nawnit Sen
    Nov 11 at 10:55






  • 1




    I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
    – farzane
    Nov 11 at 12:12


















  • Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
    – farzane
    Nov 11 at 10:38












  • if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
    – Nawnit Sen
    Nov 11 at 10:40










  • javax.persistence.RollbackException: Error while committing the transaction--->Caused by:javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
    – farzane
    Nov 11 at 10:52












  • it says table doesnt exist...just check in the db if that particular table exist or not
    – Nawnit Sen
    Nov 11 at 10:55






  • 1




    I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
    – farzane
    Nov 11 at 12:12
















Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
– farzane
Nov 11 at 10:38






Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
– farzane
Nov 11 at 10:38














if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
– Nawnit Sen
Nov 11 at 10:40




if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
– Nawnit Sen
Nov 11 at 10:40












javax.persistence.RollbackException: Error while committing the transaction--->Caused by:javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
– farzane
Nov 11 at 10:52






javax.persistence.RollbackException: Error while committing the transaction--->Caused by:javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement--->Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
– farzane
Nov 11 at 10:52














it says table doesnt exist...just check in the db if that particular table exist or not
– Nawnit Sen
Nov 11 at 10:55




it says table doesnt exist...just check in the db if that particular table exist or not
– Nawnit Sen
Nov 11 at 10:55




1




1




I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
– farzane
Nov 11 at 12:12




I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
– farzane
Nov 11 at 12:12


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237463%2fhappening-java-lang-exceptionininitializererror-caused-by-unable-to-build%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)