Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | None | 0 0
  1. Hibernate: select attendee_.attendeeId, attendee_.attendeeName as attendee2_1_ from attendee attendee_ where attendee_.attendeeId=?
  2. Hibernate: select attendee_.attendeeId, attendee_.attendeeName as attendee2_1_ from attendee attendee_ where attendee_.attendeeId=?
  3. Hibernate: insert into event (eventName, startDate, eventId) values (?, ?, ?)
  4. Hibernate: insert into attendee (attendeeName, attendeeId) values (?, ?)
  5. Hibernate: insert into attendee (attendeeName, attendeeId) values (?, ?)
  6. Hibernate: update attendee set attendeeId=? where attendeeId=?
  7. Hibernate: update attendee set attendeeId=? where attendeeId=?
  8. Aug 29, 2010 7:39:10 PM org.hibernate.util.JDBCExceptionReporter logExceptions
  9. WARNING: SQL Error: 1062, SQLState: 23000
  10. Aug 29, 2010 7:39:10 PM org.hibernate.util.JDBCExceptionReporter logExceptions
  11. SEVERE: Duplicate entry '11' for key 'PRIMARY'
  12. Aug 29, 2010 7:39:10 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
  13. SEVERE: Could not synchronize database state with session
  14. org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
  15. at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
  16. at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
  17. at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
  18. at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
  19. at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
  20. at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
  21. at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
  22. at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
  23. at com.practice.hibernate.basic.BasicOperations.main(BasicOperations.java:51)
  24. Caused by: java.sql.BatchUpdateException: Duplicate entry '11' for key 'PRIMARY'
  25. at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:665)
  26. at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
  27. at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
  28. ... 6 more
  29. Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
  30. at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
  31. at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
  32. at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
  33. at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
  34. at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
  35. at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
  36. at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
  37. at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
  38. at com.practice.hibernate.basic.BasicOperations.main(BasicOperations.java:51)
  39. Caused by: java.sql.BatchUpdateException: Duplicate entry '11' for key 'PRIMARY'
  40. at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:665)
  41. at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
  42. at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
  43. ... 6 more
  44.  
  45. public static void main(String[] args) {
  46. Session session = HibernateRuntime.getSession();
  47.  
  48. try {
  49. Set<Attendee> attendees = new HashSet<Attendee>(2);
  50.  
  51. Attendee attendee = new Attendee();
  52. attendee.setAttendeeId(3);
  53. attendee.setAttendeeName("Baswanth Rao");
  54.  
  55. Attendee attendee1 = new Attendee();
  56. attendee1.setAttendeeId(4);
  57. attendee1.setAttendeeName("Razi Ahmed");
  58.  
  59. attendees.add(attendee);
  60. attendees.add(attendee1);
  61.  
  62. Event event = new Event();
  63. event.setEventId(11);
  64. event.setEventName("Initiatives Workshop 3");
  65. event.setStartDate(new Date());
  66. event.setAttendees(attendees);
  67.  
  68. session.save(event);
  69. session.flush();
  70.  
  71. } finally {
  72. session.close();
  73. }
  74. }
  75.  
  76. <hibernate-mapping package="com.practice.hibernate.vo">
  77. <class name="Event" table="event">
  78. <id name="eventId" column="eventId" type="long">
  79. <generator class="assigned" />
  80. </id>
  81.  
  82. <property name="eventName" type="string" length="100" />
  83. <property name="startDate" type="date" />
  84.  
  85. <set name="attendees" cascade="all">
  86. <key column="attendeeId" />
  87. <one-to-many class="Attendee" />
  88. </set>
  89. </class>
  90. </hibernate-mapping>
  91.  
  92. <hibernate-configuration>
  93. <session-factory>
  94. <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  95. <property name="connection.url">jdbc:mysql://localhost/test</property>
  96. <property name="connection.username">root</property>
  97. <property name="connection.password"></property>
  98. <property name="connection.autocommit">false</property>
  99.  
  100. <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  101. <property name="show_sql">true</property>
  102.  
  103. <mapping resource="com/practice/hibernate/vo/Event.hbm.xml"></mapping>
  104. <mapping resource="com/practice/hibernate/vo/Attendee.hbm.xml"></mapping>
  105. </session-factory>
  106. </hibernate-configuration>
  107.  
  108. <set name="attendees" cascade="all">
  109. <key column="attendeeId" />
  110. <one-to-many class="Attendee" />
  111. </set>
  112.  
  113. <set name="attendees" cascade="all">
  114. <key column="event_id"/>
  115. <one-to-many class="Attendee"/>
  116. </set>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement