SHARE
TWEET

Untitled

a guest Nov 6th, 2018 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Exception in thread "main" javax.persistence.RollbackException: Error while committing the transaction
  2. at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:92)
  3. at model.bl.PersonManager.main(PersonManager.java:33)
  4. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  5. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  6. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  7. at java.lang.reflect.Method.invoke(Method.java:498)
  8. at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  9.  
  10. Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
  11. at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
  12. at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
  13. at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:80)
  14. ... 6 more
  15.  
  16. Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
  17. at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
  18. at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
  19. at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
  20. at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
  21. at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:136)
  22. at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:58)
  23. at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3058)
  24. at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3499)
  25. at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
  26. at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
  27. at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
  28. at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:275)
  29. at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:328)
  30. at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
  31. at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1233)
  32. at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:403)
  33. at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
  34. at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
  35. at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:75)
  36. ... 6 more
  37.  
  38. Caused by: java.sql.SQLSyntaxErrorException: ORA-01747: invalid user.table.column, table.column, or column specification
  39.  
  40. at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
  41. at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
  42. at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
  43. at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
  44. at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
  45. at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
  46. at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:208)
  47. at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1046)
  48. at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
  49. at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3613)
  50. at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3694)
  51. at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1354)
  52. at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)
  53. ... 20 more
  54.    
  55. package model.entity;
  56. import model.bl.PersonManager;
  57. import javax.persistence.*;
  58. import java.io.Serializable;
  59. import java.util.List;
  60.  
  61. //mapping class to table
  62. @Entity (name = "person")
  63. @Table(name = "USERS")
  64. @EntityListeners(value = PersonManager.class)
  65.  
  66. public class Person implements Serializable
  67. {
  68.  
  69. @Id // create id and fill auto by sequence in database
  70. @Column(name="UID" ,columnDefinition = "NUMBER" )
  71. @SequenceGenerator(name = "mySeq" , sequenceName = "DB_MYSEQ")
  72. @GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq")
  73. private long uId;
  74.  
  75.  
  76. @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  77. @JoinColumn(name = "FK_PERSON",referencedColumnName = "UID")
  78. private List<Pictures> picturesList;
  79.  
  80.  
  81. @Basic
  82. @Column (name = "USERNAME" , columnDefinition = "NVARCHAR2(30)" , nullable = false , unique = true)
  83. private String username ;
  84.  
  85. @Basic
  86. @Column (name = "PASSWORD" , columnDefinition = "NVARCHAR2(32)" , nullable = false , unique = true)
  87. private String  password ;
  88.  
  89. @Basic
  90. @Column (name = "EMAIL" , columnDefinition = "NVARCHAR2(40)" , nullable = false)
  91. private String email;
  92.  
  93.  
  94. @Basic
  95. @Column (name = "SEX" , columnDefinition = "NVARCHAR2(20)")
  96. private String sex ;
  97.  
  98. //--------------------------------------------------------
  99.  
  100. public Person() { }
  101.  
  102. public Person(String username, String password, String email, String sex, String userPic) {
  103.     this.username = username;
  104.     this.password = password;
  105.     this.email = email;
  106.     this.sex = sex;
  107.     this.userPic = userPic;
  108. }
  109. public Person(String username, String password, String email ,String sex, String userPic,List<Pictures> picturesList ) {
  110.     this.picturesList = picturesList;
  111.     this.sex = sex;
  112.     this.userPic = userPic;
  113.     this.email = email;
  114.     this.password = password;
  115.     this.username = username;
  116. }
  117.  
  118. //--------------------------------------------------------
  119.  
  120. public void setUsername(String username) {
  121.     this.username = username;
  122. }
  123.  
  124. public void setPassword(String password) {
  125.     this.password = password;
  126. }
  127.  
  128. public void setEmail(String email) {
  129.     this.email = email;
  130. }
  131.  
  132. public void setUserPic(String userPic) {
  133.     this.userPic = userPic;
  134. }
  135.  
  136. public void setSex(String sex) {
  137.     this.sex = sex;
  138. }
  139.  
  140. public void setuId(long uId) {this.uId = uId;}
  141.  
  142. //--------------------------------------------------------
  143.  
  144. public String getUsername() {
  145.     return username;
  146. }
  147.  
  148. public String getPassword() {
  149.     return password;
  150. }
  151.  
  152. public String getUserPic() {
  153.     return userPic;
  154. }
  155.  
  156. public String getEmail() {
  157.     return email;
  158. }
  159.  
  160. public String getSex() {
  161.     return sex;
  162. }
  163.  
  164. public long getuId() {return uId;}
  165.  
  166. }
  167. }
  168.    
  169. package model.entity;
  170.  
  171. import javax.persistence.*;
  172. import java.io.Serializable;
  173.  
  174. @Entity(name = "picture")
  175. @Table(name = "PICTURE")
  176.  
  177. public class Pictures implements Serializable
  178. {
  179. @Id // create id and fill auto by sequence in database
  180. @Column(name="PID" ,columnDefinition = "NUMBER" )
  181. @SequenceGenerator(name = "mySeq2" , sequenceName = "DB_MYSEQ2")
  182. @GeneratedValue(strategy=GenerationType.AUTO ,generator="mySeq2")
  183. private long pId;
  184.  
  185.  
  186. @Basic
  187. @Column (name = "PICADRESS" , columnDefinition = "NVARCHAR2(50)" , nullable = false)
  188. private String  picAdress ;
  189.  
  190. @Basic
  191. @Column (name = "CAPTION" , columnDefinition = "LONG")
  192. private String caption;
  193.  
  194. @Basic // user picture for profile
  195. @Column (name = "LIKES" , columnDefinition = "NUMBER")
  196. private int likes;
  197.  
  198. //--------------------------------------------------------
  199. public Pictures(){}
  200.  
  201. public Pictures( String picAdress, String caption, int likes) {
  202.     this.picAdress = picAdress;
  203.     this.caption = caption;
  204.     this.likes = likes;
  205. }
  206. //--------------------------------------------------------
  207.  
  208. public void setPid(long pid) {
  209.     this.pId = pid;
  210. }
  211.  
  212. public void setLikes(int likes) {
  213.     this.likes = likes;
  214. }
  215.  
  216. public void setPicAdress(String picAdress) {
  217.     this.picAdress = picAdress;
  218. }
  219.  
  220. public void setCaption(String caption) {
  221.     this.caption = caption;
  222. }
  223.  
  224. //--------------------------------------------------------
  225.  
  226. public int getLikes() {
  227.     return likes;
  228. }
  229.  
  230. public String getCaption() {
  231.     return caption;
  232. }
  233.  
  234. public String getPicAdress() {
  235.     return picAdress;
  236. }
  237.  
  238. public long getPid() {
  239.     return pId;
  240. }
  241. }
  242.    
  243. public class JPAProvider {
  244.  
  245.     private static final EntityManagerFactory     entityManagerFactory;//instate of session for connect to database
  246.     static{
  247.         entityManagerFactory  = Persistence.createEntityManagerFactory("MyConnection");
  248.     }
  249.  
  250.     public static EntityManagerFactory getEntityManagerFactory() {
  251.         return entityManagerFactory;
  252.    }
  253. }
  254.    
  255. public class PersonManager {
  256.  
  257.     public static void main(String[] args) {
  258.  
  259.         EntityManager entityManager = JPAProvider.getEntityManagerFactory().createEntityManager();
  260.         EntityTransaction entityTransaction = entityManager.getTransaction();
  261.         entityTransaction.begin();
  262.  
  263.         Pictures pictures = new Pictures("aaa" , "akflkkgl" ,2);
  264.         Pictures pictures2 = new Pictures("nnbnbn" , "affddA" ,5);
  265.         List<Pictures> picturesList =new ArrayList<Pictures>();
  266.         picturesList.add(pictures);
  267.         picturesList.add(pictures2);
  268.         Person person = new Person("midas" , "midas123" , "aaaaa@gmail.com", "female" ,"female-user.png",picturesList );
  269.  
  270.         entityManager.persist(person);
  271.         entityTransaction.commit();
  272.         entityManager.close();
  273.     }
  274. }
  275.    
  276. <persistence-unit name="MyConnection" transaction-type="RESOURCE_LOCAL">
  277.     <provider>org.hibernate.ejb.HibernatePersistence</provider>
  278.     <properties>
  279.         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
  280.         <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
  281.         <property name="hibernate.connection.username" value="midas"/>
  282.         <property name="hibernate.connection.password" value="midas123"/>
  283.         <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
  284.         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
  285.         <property name="show_sql" value="true"></property>
  286.     </properties>
  287. </persistence-unit>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top