These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: two flushes tries to insert a join-table row twice
PostPosted: Wed Oct 05, 2005 3:04 pm 
Beginner
Beginner

Joined: Thu May 05, 2005 4:49 pm
Posts: 30
Hibernate version: 3.1 beta 3

Mapping documents:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.lodgingservices.domain">
   
   <class name="Activity" table="activities">
     
      <!-- ============================== Common Elements -->
     
      <id name="id" unsaved-value="null">
         <generator class="native"/>
      </id>
     
      <discriminator column="activity_type" type="string" force="false"/>
     
      <version name="version"/>
     
      <property name="created" type="timestamp"/>
     
      <!-- ============================== Properties and Associations -->
     
      <property name="active" column="is_active" type="boolean" not-null="true"/>
     
      <set name="deals" table="activity_deals" sort="natural" cascade="save-update">
         <key column="activity_id"/>
         <many-to-many class="Deal" column="deal_id"/>
      </set>
     
      <property name="displayedInMenu" column="displayed_in_menu" type="boolean"
         not-null="true"/>
     
      <property name="time" type="text"/>
     
      <property name="largeDescription" column="large_description" type="text"/>
     
      <many-to-one name="largePicture" class="Picture" column="large_picture_id"
         unique="true" cascade="all"/>
     
      <property name="name" not-null="true"/>
     
      <property name="policies" type="text"/>
     
      <property name="rateAlias" column="rate_alias" not-null="false"/>
     
      <property name="ratesDisplayedInMenu" column="rates_displayed_in_menu"
         type="boolean" not-null="true"/>
     
      <set name="rateSets" cascade="all-delete-orphan" sort="natural"
         inverse="true">
         <key column="activity_id"/>
         <one-to-many class="RateSet"/>
      </set>
     
      <property name="rateSetUnit" column="rate_set_unit" />
     
      <property name="reservations" type="text"/>
     
      <property name="seasonalDescription" type="text"
         column="seasonal_description"/>
     
      <property name="smallDescription" column="small_description" type="text"/>
     
      <many-to-one name="smallPicture" class="Picture" column="small_picture_id"
         unique="true" cascade="all"/>
     
      <property name="website" type="com.slickapps.hibernate.URLUserType"/>
     
      <!-- ============================== Subclasses -->
     
      <subclass name="com.lodgingservices.domain.resort.ResortActivity"
         discriminator-value="resort">
         <many-to-one name="resort"
            class="com.lodgingservices.domain.resort.Resort"
            column="resort_activity_id" not-null="false"/>
      </subclass>
     
      <subclass name="com.lodgingservices.domain.destination.DestinationActivity"
         discriminator-value="destination">
         <set name="destinations" table="destination_activities"
            cascade="save-update">
            <key column="activity_id"/>
            <many-to-many column="destination_id"
               class="com.lodgingservices.domain.destination.Destination"/>
         </set>
      </subclass>
     
      <subclass name="com.lodgingservices.domain.resort.LodgingActivity"
         discriminator-value="lodging">
         <one-to-one name="resort"
            class="com.lodgingservices.domain.resort.Resort"
            property-ref="lodgingActivity" constrained="true"/>
      </subclass>
     
      <subclass name="com.lodgingservices.domain.Event"
         discriminator-value="event">
         
         <property name="date" type="date" column="date" not-null="false"/>
         
         <property name="endDate" type="date" column="end_date" not-null="false"/>
         
         <property name="location" type="text"/>
         
         <subclass name="com.lodgingservices.domain.resort.ResortEvent"
            discriminator-value="resort_event">
            <many-to-one name="resort"
               class="com.lodgingservices.domain.resort.Resort"
               column="resort_event_id" not-null="false"/>
         </subclass>
         
         <subclass name="com.lodgingservices.domain.destination.DestinationEvent"
            discriminator-value="destination_event">
            <set name="destinations" table="destination_events"
               cascade="save-update">
               <key column="event_id"/>
               <many-to-many column="destination_id"
                  class="com.lodgingservices.domain.destination.Destination"/>
            </set>
         </subclass>
         
      </subclass>
     
   </class>
   
</hibernate-mapping>


and

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.lodgingservices.domain">
   
   <class name="Deal" table="deals">
     
      <!-- ============================== Common Elements -->
     
      <id name="id">
         <generator class="native"/>
      </id>
     
      <version name="version"/>
     
      <property name="created" type="timestamp"/>
     
      <!-- ============================== Properties and Associations -->
     
      <set name="activities" table="activity_deals" sort="natural" inverse="true"
         cascade="save-update">
         <key column="deal_id"/>
         <many-to-many class="Activity" column="activity_id"/>
      </set>
     
      <property name="finePrint" column="fine_print" type="text"/>
     
      <list name="includedFeatures" table="deal_included_features">
         <key column="deal_id"/>
         <list-index column="order_id"/>
         <element column="feature" type="text"/>
      </list>
     
      <property name="largeDescription" column="large_description" type="text"/>
     
      <many-to-one name="largePicture" class="Picture" column="large_picture_id"
         unique="true" cascade="all"/>
     
      <property name="name" column="name"/>
     
      <set name="sites" table="site_deals" sort="natural" inverse="true"
         cascade="save-update">
         <key column="deal_id"/>
         <many-to-many class="Site" column="site_id"/>
      </set>
     
      <property name="smallDescription" column="small_description" type="text"/>
     
      <many-to-one name="smallPicture" class="Picture" column="small_picture_id"
         unique="true" cascade="all"/>
     
      <property name="startDate" column="start_date" type="date"/>
     
      <property name="stopDate" column="stop_date" type="date"/>
     
   </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
@SuppressWarnings("unchecked")
   public void testActivity_details() throws Exception {
      // Resort resort = saveNewResort("Test Resort");
      Deal deal = saveNewDeal("Test Deal");
      Activity activity = saveNewResortActivity("Test Resort Activity");
      activity.addDeal(deal);
     
      request.addParameter("activityId", String.valueOf(activity.getId()));

      // test active deal dates
      deal.setStartDate(DateUtil.getTodayWithoutTime());
      deal.setStopDate(java.sql.Date.valueOf("2050-01-01"));
      hibernateUtil.flush();
     
      modelView = smc.activity_details(request, response);
      model = modelView.getModel();
      Map<Long, Long> activityFirstDealIds = (Map<Long, Long>)model.get("activityFirstDealIds");
      assertTrue(activityFirstDealIds.size() == 1);
      assertTrue(activityFirstDealIds.get(activity.getId()) == deal.getId());

      // test expired deal dates
      deal.setStartDate(java.sql.Date.valueOf("1995-01-01"));
      deal.setStopDate(java.sql.Date.valueOf("1996-01-01"));
      hibernateUtil.flush();
      modelView = smc.activity_details(request, response);
      model = modelView.getModel();
      activityFirstDealIds = (Map<Long, Long>)model.get("activityFirstDealIds");
      assertTrue(activityFirstDealIds.size() == 0);
   }

   // --------------------------- Helper Methods

   private Resort saveNewResort(String name) {
      Resort r = new Resort();
      r.setName(name);
      commonResources.getResortDao().saveOrUpdate(r);
      return r;
   }

   private ResortActivity saveNewResortActivity(String name) {
      ResortActivity a = new ResortActivity();
      a.setName(name);
      commonResources.getActivityDao().saveOrUpdate(a);
      return a;
   }

   private Deal saveNewDeal(String name) {
      Deal d = new Deal();
      d.setName(name);
      commonResources.getDealDao().saveOrUpdate(d);
      return d;
   }

Full stack trace of any exception that occurs:
Code:
tests:
    [junit] Testsuite: com.lodgingservices.test.data.Test_ActivityDaoImpl
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 6.328 sec

    [junit] Testsuite: com.lodgingservices.test.web.Test_SharedMultiController
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.125 sec

    [junit] Testcase: testActivity_details(com.lodgingservices.test.web.Test_Sha
redMultiController):    Caused an ERROR
    [junit] Hibernate operation: Could not execute JDBC batch update; SQL [inser
t into activity_deals (activity_id, deal_id) values (?, ?)]; Duplicate entry '24
0-36' for key 1; nested exception is java.sql.BatchUpdateException: Duplicate en
try '240-36' for key 1
    [junit] org.springframework.dao.DataIntegrityViolationException: Hibernate o
peration: Could not execute JDBC batch update; SQL [insert into activity_deals (
activity_id, deal_id) values (?, ?)]; Duplicate entry '240-36' for key 1; nested
exception is java.sql.BatchUpdateException: Duplicate entry '240-36' for key 1
    [junit] java.sql.BatchUpdateException: Duplicate entry '240-36' for key 1
    [junit]     at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStateme
nt.java:891)
    [junit]     at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBat
cher.java:58)
    [junit]     at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatch
er.java:193)
    [junit]     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.j
ava:230)
    [junit]     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.j
ava:143)
    [junit]     at org.hibernate.event.def.AbstractFlushingEventListener.perform
Executions(AbstractFlushingEventListener.java:296)
    [junit]     at org.hibernate.event.def.DefaultFlushEventListener.onFlush(Def
aultFlushEventListener.java:27)
    [junit]     at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:877)
    [junit]     at org.springframework.orm.hibernate3.HibernateTemplate$27.doInH
ibernate(HibernateTemplate.java:771)
    [junit]     at org.springframework.orm.hibernate3.HibernateTemplate.execute(
HibernateTemplate.java:358)
    [junit]     at org.springframework.orm.hibernate3.HibernateTemplate.flush(Hi
bernateTemplate.java:769)
    [junit]     at com.slickapps.util.HibernateUtil.flush(HibernateUtil.java:16)

    [junit]     at com.lodgingservices.test.web.Test_SharedMultiController.testA
ctivity_details(Test_SharedMultiController.java:85)


    [junit] TEST com.lodgingservices.test.web.Test_SharedMultiController FAILED
    [junit] Tests FAILED

BUILD FAILED
C:\webapps\Lodging Services\build.xml:21: The following error occurred while exe
cuting this line:
C:\webapps\build.xml:205: -
         **********************************************************
         ****  One or more tests failed! Check the output ...  ****
         **********************************************************

Name and version of the database you are using:
MySQL 5.0.13

The generated SQL (show_sql=true):
Code:
SET autocommit=0
          220 Query       insert into deals (version, created, fine_print, large_description, large_picture_id, name, small_description, small_picture_id, start_date, stop_date) values (0, '2005-10-05 12:47:26', null, null, null, 'Test Deal', null, null, null, null)
          220 Query       insert into activities (version, created, is_active, displayed_in_menu, time, large_description, large_picture_id, name, policies, rate_alias, rates_displayed_in_menu, rate_set_unit, reservations, seasonal_description, small_description, small_picture_id, website, resort_activity_id, activity_type) values (0, '2005-10-05 12:47:26', '1', '0', null, null, null, 'Test Resort Activity', null, null, '0', null, null, null, null, null, null, null, 'resort')
          220 Query       update deals set version=1, created='2005-10-05 12:47:26', fine_print=null, large_description=null, large_picture_id=null, name='Test Deal', small_description=null, small_picture_id=null, start_date='2005-10-05', stop_date='2050-01-01' where id=36 and version=0
          220 Query       update activities set version=1, created='2005-10-05 12:47:26', is_active='1', displayed_in_menu='0', time=null, large_description=null, large_picture_id=null, name='Test Resort Activity', policies=null, rate_alias=null, rates_displayed_in_menu='0', rate_set_unit=null, reservations=null, seasonal_description=null, small_description=null, small_picture_id=null, website=null, resort_activity_id=null where id=240 and version=0
          220 Query       insert into activity_deals (activity_id, deal_id) values (240, 36)
          220 Query       update deals set version=2, created='2005-10-05 12:47:26', fine_print=null, large_description=null, large_picture_id=null, name='Test Deal', small_description=null, small_picture_id=null, start_date='1995-01-01', stop_date='1996-01-01' where id=36 and version=1
          220 Query       update activities set version=2, created='2005-10-05 12:47:26', is_active='1', displayed_in_menu='0', time=null, large_description=null, large_picture_id=null, name='Test Resort Activity', policies=null, rate_alias=null, rates_displayed_in_menu='0', rate_set_unit=null, reservations=null, seasonal_description=null, small_description=null, small_picture_id=null, website=null, resort_activity_id=null where id=240 and version=1
          220 Query       insert into activity_deals (activity_id, deal_id) values (240, 36)
          220 Query       rollback


Debug level Hibernate log excerpt:
Code:
2005-10-05 12:55:01,703 DEBUG (AbstractSaveEventListener.java:461) - transient instance of: com.lodgingservices.domain.resort.Resort
2005-10-05 12:55:01,703 DEBUG (DefaultSaveOrUpdateEventListener.java:161) - saving transient instance
2005-10-05 12:55:01,718 DEBUG (AbstractSaveEventListener.java:139) - saving [com.lodgingservices.domain.resort.Resort#<null>]
2005-10-05 12:55:01,718 DEBUG (AbstractSaveEventListener.java:221) - executing insertions
2005-10-05 12:55:01,718 DEBUG (AbstractSaveEventListener.java:461) - transient instance of: com.lodgingservices.domain.resort.LodgingActivity
2005-10-05 12:55:01,718 DEBUG (DefaultSaveOrUpdateEventListener.java:161) - saving transient instance
2005-10-05 12:55:01,718 DEBUG (AbstractSaveEventListener.java:139) - saving [com.lodgingservices.domain.resort.LodgingActivity#<null>]
2005-10-05 12:55:01,718 DEBUG (AbstractSaveEventListener.java:221) - executing insertions
2005-10-05 12:55:01,734 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.Activity.deals
2005-10-05 12:55:01,734 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.Activity.rateSets
2005-10-05 12:55:01,734 DEBUG (AbstractBatcher.java:344) - insert into activities (version, created, is_active, displayed_in_menu, time, large_description, large_picture_id, name, policies, rate_alias, rates_displayed_in_menu, rate_set_unit, reservations, seasonal_description, small_description, small_picture_id, website, activity_type) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'lodging')
2005-10-05 12:55:01,765 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.resort.Resort.activities
2005-10-05 12:55:01,765 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.resort.Resort.amenities
2005-10-05 12:55:01,765 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.resort.Resort.events
2005-10-05 12:55:01,765 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.resort.Resort.faqs
2005-10-05 12:55:01,765 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.resort.Resort.features
2005-10-05 12:55:01,765 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.resort.Resort.pictureGroups
2005-10-05 12:55:01,765 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.resort.Resort.roomCategories
2005-10-05 12:55:01,765 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.resort.Resort.testimonials
2005-10-05 12:55:01,765 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.resort.Resort.videos
2005-10-05 12:55:01,765 DEBUG (AbstractBatcher.java:344) - insert into resorts (version, created, address_line1, address_line2, address_city, address_state, address_zip, address_country, amenities_fine_print, amenities_picture_id, latitude, longitude, coordinates_override, description, destination_id, directions, lodging_activity_id, logo_picture_name, main_picture_id, name, stars) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2005-10-05 12:55:01,781 DEBUG (AbstractSaveEventListener.java:461) - transient instance of: com.lodgingservices.domain.resort.ResortActivity
2005-10-05 12:55:01,781 DEBUG (DefaultSaveOrUpdateEventListener.java:161) - saving transient instance
2005-10-05 12:55:01,781 DEBUG (AbstractSaveEventListener.java:139) - saving [com.lodgingservices.domain.resort.ResortActivity#<null>]
2005-10-05 12:55:01,781 DEBUG (AbstractSaveEventListener.java:221) - executing insertions
2005-10-05 12:55:01,781 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.Activity.deals
2005-10-05 12:55:01,781 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.Activity.rateSets
2005-10-05 12:55:01,781 DEBUG (AbstractBatcher.java:344) - insert into activities (version, created, is_active, displayed_in_menu, time, large_description, large_picture_id, name, policies, rate_alias, rates_displayed_in_menu, rate_set_unit, reservations, seasonal_description, small_description, small_picture_id, website, resort_activity_id, activity_type) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'resort')
2005-10-05 12:55:01,843 DEBUG (AbstractSaveEventListener.java:461) - transient instance of: com.lodgingservices.domain.Deal
2005-10-05 12:55:01,843 DEBUG (DefaultSaveOrUpdateEventListener.java:161) - saving transient instance
2005-10-05 12:55:01,843 DEBUG (AbstractSaveEventListener.java:139) - saving [com.lodgingservices.domain.Deal#<null>]
2005-10-05 12:55:01,843 DEBUG (AbstractSaveEventListener.java:221) - executing insertions
2005-10-05 12:55:01,843 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.Deal.activities
2005-10-05 12:55:01,843 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.Deal.includedFeatures
2005-10-05 12:55:01,843 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.Deal.sites
2005-10-05 12:55:01,843 DEBUG (AbstractBatcher.java:344) - insert into deals (version, created, fine_print, large_description, large_picture_id, name, small_description, small_picture_id, start_date, stop_date) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2005-10-05 12:55:01,843 DEBUG (AbstractSaveEventListener.java:461) - transient instance of: com.lodgingservices.domain.resort.ResortActivity
2005-10-05 12:55:01,859 DEBUG (DefaultSaveOrUpdateEventListener.java:161) - saving transient instance
2005-10-05 12:55:01,859 DEBUG (AbstractSaveEventListener.java:139) - saving [com.lodgingservices.domain.resort.ResortActivity#<null>]
2005-10-05 12:55:01,859 DEBUG (AbstractSaveEventListener.java:221) - executing insertions
2005-10-05 12:55:01,859 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.Activity.deals
2005-10-05 12:55:01,859 DEBUG (WrapVisitor.java:87) - Wrapped collection in role: com.lodgingservices.domain.Activity.rateSets
2005-10-05 12:55:01,859 DEBUG (AbstractBatcher.java:344) - insert into activities (version, created, is_active, displayed_in_menu, time, large_description, large_picture_id, name, policies, rate_alias, rates_displayed_in_menu, rate_set_unit, reservations, seasonal_description, small_description, small_picture_id, website, resort_activity_id, activity_type) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'resort')
2005-10-05 12:55:01,859 DEBUG (AbstractFlushingEventListener.java:58) - flushing session
2005-10-05 12:55:01,859 DEBUG (AbstractFlushingEventListener.java:111) - processing flush-time cascades
2005-10-05 12:55:01,859 DEBUG (AbstractSaveEventListener.java:435) - persistent instance of: com.lodgingservices.domain.Activity
2005-10-05 12:55:01,859 DEBUG (DefaultSaveOrUpdateEventListener.java:105) - ignoring persistent instance
2005-10-05 12:55:01,859 DEBUG (DefaultSaveOrUpdateEventListener.java:142) - object already associated with session: [com.lodgingservices.domain.resort.ResortActivity#243]
2005-10-05 12:55:01,859 DEBUG (AbstractSaveEventListener.java:435) - persistent instance of: com.lodgingservices.domain.Deal
2005-10-05 12:55:01,859 DEBUG (DefaultSaveOrUpdateEventListener.java:105) - ignoring persistent instance
2005-10-05 12:55:01,859 DEBUG (DefaultSaveOrUpdateEventListener.java:142) - object already associated with session: [com.lodgingservices.domain.Deal#37]
2005-10-05 12:55:01,859 DEBUG (AbstractFlushingEventListener.java:153) - dirty checking collections
2005-10-05 12:55:01,859 DEBUG (AbstractFlushingEventListener.java:170) - Flushing entities and processing referenced collections
2005-10-05 12:55:01,875 DEBUG (DefaultFlushEntityEventListener.java:212) - Updating entity: [com.lodgingservices.domain.Deal#37]
2005-10-05 12:55:01,875 DEBUG (DefaultFlushEntityEventListener.java:212) - Updating entity: [com.lodgingservices.domain.resort.ResortActivity#243]
2005-10-05 12:55:01,875 DEBUG (AbstractFlushingEventListener.java:209) - Processing unreferenced collections
2005-10-05 12:55:01,875 DEBUG (AbstractFlushingEventListener.java:223) - Scheduling collection removes/(re)creates/updates
2005-10-05 12:55:01,875 DEBUG (AbstractFlushingEventListener.java:85) - Flushed: 0 insertions, 2 updates, 0 deletions to 2 objects
2005-10-05 12:55:01,875 DEBUG (AbstractFlushingEventListener.java:91) - Flushed: 5 (re)creations, 0 updates, 0 removals to 5 collections
2005-10-05 12:55:01,875 DEBUG (AbstractFlushingEventListener.java:289) - executing flush
2005-10-05 12:55:01,875 DEBUG (AbstractBatcher.java:344) - update deals set version=?, created=?, fine_print=?, large_description=?, large_picture_id=?, name=?, small_description=?, small_picture_id=?, start_date=?, stop_date=? where id=? and version=?
2005-10-05 12:55:01,890 DEBUG (AbstractBatcher.java:344) - update activities set version=?, created=?, is_active=?, displayed_in_menu=?, time=?, large_description=?, large_picture_id=?, name=?, policies=?, rate_alias=?, rates_displayed_in_menu=?, rate_set_unit=?, reservations=?, seasonal_description=?, small_description=?, small_picture_id=?, website=?, resort_activity_id=? where id=? and version=?
2005-10-05 12:55:01,890 DEBUG (AbstractBatcher.java:344) - insert into activity_deals (activity_id, deal_id) values (?, ?)
2005-10-05 12:55:01,890 DEBUG (AbstractFlushingEventListener.java:316) - post flush
2005-10-05 12:55:01,906 DEBUG (DefaultLoadEventListener.java:153) - loading entity: [com.lodgingservices.domain.Activity#243]
2005-10-05 12:55:01,906 DEBUG (DefaultLoadEventListener.java:304) - attempting to resolve: [com.lodgingservices.domain.Activity#243]
2005-10-05 12:55:01,906 DEBUG (DefaultLoadEventListener.java:313) - resolved object in session cache: [com.lodgingservices.domain.Activity#243]
2005-10-05 12:55:01,906 DEBUG (DefaultLoadEventListener.java:153) - loading entity: [com.lodgingservices.domain.Deal#37]
2005-10-05 12:55:01,906 DEBUG (DefaultLoadEventListener.java:304) - attempting to resolve: [com.lodgingservices.domain.Deal#37]
2005-10-05 12:55:01,906 DEBUG (DefaultLoadEventListener.java:313) - resolved object in session cache: [com.lodgingservices.domain.Deal#37]
2005-10-05 12:55:01,906 DEBUG (AbstractFlushingEventListener.java:58) - flushing session
2005-10-05 12:55:01,906 DEBUG (AbstractFlushingEventListener.java:111) - processing flush-time cascades
2005-10-05 12:55:01,906 DEBUG (AbstractSaveEventListener.java:435) - persistent instance of: com.lodgingservices.domain.Activity
2005-10-05 12:55:01,906 DEBUG (DefaultSaveOrUpdateEventListener.java:105) - ignoring persistent instance
2005-10-05 12:55:01,906 DEBUG (DefaultSaveOrUpdateEventListener.java:142) - object already associated with session: [com.lodgingservices.domain.resort.ResortActivity#243]
2005-10-05 12:55:01,906 DEBUG (AbstractSaveEventListener.java:435) - persistent instance of: com.lodgingservices.domain.Deal
2005-10-05 12:55:01,921 DEBUG (DefaultSaveOrUpdateEventListener.java:105) - ignoring persistent instance
2005-10-05 12:55:01,921 DEBUG (DefaultSaveOrUpdateEventListener.java:142) - object already associated with session: [com.lodgingservices.domain.Deal#37]
2005-10-05 12:55:01,921 DEBUG (AbstractFlushingEventListener.java:153) - dirty checking collections
2005-10-05 12:55:01,921 DEBUG (AbstractFlushingEventListener.java:170) - Flushing entities and processing referenced collections
2005-10-05 12:55:01,921 DEBUG (DefaultFlushEntityEventListener.java:212) - Updating entity: [com.lodgingservices.domain.Deal#37]
2005-10-05 12:55:01,921 DEBUG (DefaultFlushEntityEventListener.java:212) - Updating entity: [com.lodgingservices.domain.resort.ResortActivity#243]
2005-10-05 12:55:01,921 DEBUG (AbstractFlushingEventListener.java:209) - Processing unreferenced collections
2005-10-05 12:55:01,921 DEBUG (AbstractFlushingEventListener.java:223) - Scheduling collection removes/(re)creates/updates
2005-10-05 12:55:01,921 DEBUG (AbstractFlushingEventListener.java:85) - Flushed: 0 insertions, 2 updates, 0 deletions to 2 objects
2005-10-05 12:55:01,921 DEBUG (AbstractFlushingEventListener.java:91) - Flushed: 0 (re)creations, 1 updates, 0 removals to 5 collections
2005-10-05 12:55:01,921 DEBUG (AbstractFlushingEventListener.java:289) - executing flush
2005-10-05 12:55:01,921 DEBUG (AbstractBatcher.java:344) - update deals set version=?, created=?, fine_print=?, large_description=?, large_picture_id=?, name=?, small_description=?, small_picture_id=?, start_date=?, stop_date=? where id=? and version=?
2005-10-05 12:55:01,921 DEBUG (AbstractBatcher.java:344) - update activities set version=?, created=?, is_active=?, displayed_in_menu=?, time=?, large_description=?, large_picture_id=?, name=?, policies=?, rate_alias=?, rates_displayed_in_menu=?, rate_set_unit=?, reservations=?, seasonal_description=?, small_description=?, small_picture_id=?, website=?, resort_activity_id=? where id=? and version=?
2005-10-05 12:55:01,921 DEBUG (AbstractBatcher.java:344) - insert into activity_deals (activity_id, deal_id) values (?, ?)
2005-10-05 12:55:01,937 ERROR (AbstractFlushingEventListener.java:299) - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:200)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:877)
   at org.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(HibernateTemplate.java:771)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358)
   at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:769)
   at com.slickapps.util.HibernateUtil.flush(HibernateUtil.java:16)
   at com.lodgingservices.test.web.Test_SharedMultiController.testActivity_details(Test_SharedMultiController.java:85)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:297)
   at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:672)
   at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:546)
Caused by: java.sql.BatchUpdateException: Duplicate entry '243-37' for key 1
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:891)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:193)
   ... 25 more


Whew! ok... my problem is that when I run the above code in my unit test function, I call flush() twice. Once before I update two properties (startDate and stopDate) of Deal, and once after. The second time I call flush(), it correctly generates an update() statement, but also tries to insert a second identical row in the join table activity_deals, which fails due to a non-unique-key problem.

Why is Hibernate trying to insert the row twice? I've verified that after the first flush(), Activity and Deal are both persistent and have both been inserted into their respective tables, and join table.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 06, 2005 4:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Simplify your code and submit a very simple runnable test case to JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 06, 2005 4:33 am 
Beginner
Beginner

Joined: Thu May 05, 2005 4:49 pm
Posts: 30
thanks for checkin in, working on the testcase...


Top
 Profile  
 
 Post subject: Jira
PostPosted: Thu Oct 06, 2005 6:04 am 
Beginner
Beginner

Joined: Thu May 05, 2005 4:49 pm
Posts: 30
Opened JIRA issue at http://opensource.atlassian.com/project ... e/HHH-1018


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.