happening “ java.lang.ExceptionInInitializerError ” Caused by “ Unable to build EntityManagerFactory ” in JPA project
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.
java hibernate jpa model-view-controller
New contributor
|
show 7 more comments
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.
java hibernate jpa model-view-controller
New contributor
Is the schema already created on the database?
– Michael Wiles
yesterday
@MichaelWiles No ، Not made.
– farzane
yesterday
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
yesterday
@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
yesterday
looks like columnUID
is not present can you changehm2ddl
property to<property name="hibernate.hbm2ddl.auto" value="create"/>
and try
– Nawnit Sen
yesterday
|
show 7 more comments
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.
java hibernate jpa model-view-controller
New contributor
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
java hibernate jpa model-view-controller
New contributor
New contributor
edited 19 hours ago
New contributor
asked yesterday
farzane
53
53
New contributor
New contributor
Is the schema already created on the database?
– Michael Wiles
yesterday
@MichaelWiles No ، Not made.
– farzane
yesterday
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
yesterday
@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
yesterday
looks like columnUID
is not present can you changehm2ddl
property to<property name="hibernate.hbm2ddl.auto" value="create"/>
and try
– Nawnit Sen
yesterday
|
show 7 more comments
Is the schema already created on the database?
– Michael Wiles
yesterday
@MichaelWiles No ، Not made.
– farzane
yesterday
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
yesterday
@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
yesterday
looks like columnUID
is not present can you changehm2ddl
property to<property name="hibernate.hbm2ddl.auto" value="create"/>
and try
– Nawnit Sen
yesterday
Is the schema already created on the database?
– Michael Wiles
yesterday
Is the schema already created on the database?
– Michael Wiles
yesterday
@MichaelWiles No ، Not made.
– farzane
yesterday
@MichaelWiles No ، Not made.
– farzane
yesterday
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
yesterday
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
yesterday
@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
yesterday
@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
yesterday
looks like column
UID
is not present can you change hm2ddl
property to <property name="hibernate.hbm2ddl.auto" value="create"/>
and try– Nawnit Sen
yesterday
looks like column
UID
is not present can you change hm2ddl
property to <property name="hibernate.hbm2ddl.auto" value="create"/>
and try– Nawnit Sen
yesterday
|
show 7 more comments
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?"
Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
– farzane
16 hours ago
if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
– Nawnit Sen
16 hours ago
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
16 hours ago
it says table doesnt exist...just check in the db if that particular table exist or not
– Nawnit Sen
16 hours ago
1
I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
– farzane
15 hours ago
|
show 2 more comments
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?"
Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
– farzane
16 hours ago
if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
– Nawnit Sen
16 hours ago
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
16 hours ago
it says table doesnt exist...just check in the db if that particular table exist or not
– Nawnit Sen
16 hours ago
1
I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
– farzane
15 hours ago
|
show 2 more comments
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?"
Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
– farzane
16 hours ago
if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
– Nawnit Sen
16 hours ago
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
16 hours ago
it says table doesnt exist...just check in the db if that particular table exist or not
– Nawnit Sen
16 hours ago
1
I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
– farzane
15 hours ago
|
show 2 more comments
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?"
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?"
answered 17 hours ago
Nawnit Sen
31225
31225
Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
– farzane
16 hours ago
if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
– Nawnit Sen
16 hours ago
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
16 hours ago
it says table doesnt exist...just check in the db if that particular table exist or not
– Nawnit Sen
16 hours ago
1
I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
– farzane
15 hours ago
|
show 2 more comments
Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
– farzane
16 hours ago
if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
– Nawnit Sen
16 hours ago
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
16 hours ago
it says table doesnt exist...just check in the db if that particular table exist or not
– Nawnit Sen
16 hours ago
1
I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
– farzane
15 hours ago
Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
– farzane
16 hours ago
Thanks so much for your follow up and help . This error seems to be fixed , but I encountered another error :(
– farzane
16 hours ago
if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
– Nawnit Sen
16 hours ago
if you find my answer helpful please mark it is accepted.:) BTW what is another error that you are getting?
– Nawnit Sen
16 hours ago
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
16 hours ago
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
16 hours ago
it says table doesnt exist...just check in the db if that particular table exist or not
– Nawnit Sen
16 hours ago
it says table doesnt exist...just check in the db if that particular table exist or not
– Nawnit Sen
16 hours ago
1
1
I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
– farzane
15 hours ago
I created my table by sql plus and run program . program was run correctly. tank you Nawinit Sen :)
– farzane
15 hours ago
|
show 2 more comments
farzane is a new contributor. Be nice, and check out our Code of Conduct.
farzane is a new contributor. Be nice, and check out our Code of Conduct.
farzane is a new contributor. Be nice, and check out our Code of Conduct.
farzane is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Is the schema already created on the database?
– Michael Wiles
yesterday
@MichaelWiles No ، Not made.
– farzane
yesterday
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
yesterday
@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
yesterday
looks like column
UID
is not present can you changehm2ddl
property to<property name="hibernate.hbm2ddl.auto" value="create"/>
and try– Nawnit Sen
yesterday