[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4866) Insert trying to insert values in the wrong order

Neil Stickels (JIRA) noreply at atlassian.com
Sat Jan 30 21:47:32 EST 2010


Insert trying to insert values in the wrong order
-------------------------------------------------

                 Key: HHH-4866
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4866
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.3.1
         Environment: Using Hibernate 3.3.1 in JBoss 5.0.0, connecting to a MySQL 5.0 database
            Reporter: Neil Stickels


It appears for all of my inserts where I have multiple parameters of the same type, it will mix up the order.  

I am pretty new to Hibernate, so possibly I have something wrong.  Here are what I think are the relevant files:

StoreBrand.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jan 10, 2010 12:38:41 AM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
    <class name="com.shopperapp.dao.StoreBrand" table="STORE_BRANDS" catalog="shopper_app">
        <composite-id name="id" class="com.shopperapp.dao.StoreBrandId">
            <key-property name="storeId" type="int">
                <column name="STORE_ID" />
            </key-property>
            <key-property name="brandId" type="int">
                <column name="BRAND_ID" />
            </key-property>
        </composite-id>
        <many-to-one name="brand" class="com.shopperapp.dao.Brand" update="false" insert="false" fetch="select">
            <column name="BRAND_ID" not-null="true" />
        </many-to-one>
        <many-to-one name="store" class="com.shopperapp.dao.Store" update="false" insert="false" fetch="select">
            <column name="STORE_ID" not-null="true" />
        </many-to-one>
    </class>
</hibernate-mapping>

Bean calling the persistence code:

	StoreBrand sb = new StoreBrand(sbid, brand, store);
	StoreBrandHome sbHome = new StoreBrandHome();
	sbHome.persist(sb);

StoreBrandHome which does the persistence:

	public void persist(StoreBrand transientInstance) {
		log.debug("persisting StoreBrand instance");
		try {
			sessionFactory.getCurrentSession().beginTransaction();
			System.out.println("trying to persist store_id "+transientInstance.getStore().getId()+" and brand_id "+transientInstance.getBrand().getId());
			sessionFactory.getCurrentSession().persist(transientInstance);
			sessionFactory.getCurrentSession().getTransaction().commit();
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}


As you can see, I have a debug statement before the insert showing the store_id and the brand_id that I am trying to persist.  When I turn on the debug, this is what I see in the server.log:

2010-01-30 20:34:37,194 DEBUG [org.hibernate.jdbc.ConnectionManager] (http-0.0.0.0-8080-2) opening JDBC connection
2010-01-30 20:34:37,195 INFO  [STDOUT] (http-0.0.0.0-8080-2) trying to persist store_id 1 and brand_id 9
2010-01-30 20:34:37,195 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] (http-0.0.0.0-8080-2) generated identifier: component[storeId,brandId]{brandId=1, storeId=9}, using strategy: org.hibernate.id.Assigned
2010-01-30 20:34:37,195 DEBUG [org.hibernate.transaction.JDBCTransaction] (http-0.0.0.0-8080-2) commit
2010-01-30 20:34:37,195 DEBUG [org.hibernate.pretty.Printer] (http-0.0.0.0-8080-2) listing entities:
2010-01-30 20:34:37,195 DEBUG [org.hibernate.pretty.Printer] (http-0.0.0.0-8080-2) com.shopperapp.dao.StoreBrand{id=component[storeId,brandId]{brandId=1, storeId=9}, store=com.shopperapp.dao.Store#1, brand=com.shopperapp.dao.Brand#9}
2010-01-30 20:34:37,195 DEBUG [org.hibernate.jdbc.AbstractBatcher] (http-0.0.0.0-8080-2) about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2010-01-30 20:34:37,195 DEBUG [org.hibernate.SQL] (http-0.0.0.0-8080-2) insert into shopper_app.STORE_BRANDS (STORE_ID, BRAND_ID) values (?, ?)
2010-01-30 20:34:37,195 INFO  [STDOUT] (http-0.0.0.0-8080-2) Hibernate: insert into shopper_app.STORE_BRANDS (STORE_ID, BRAND_ID) values (?, ?)
2010-01-30 20:34:37,198 DEBUG [org.hibernate.jdbc.AbstractBatcher] (http-0.0.0.0-8080-2) Executing batch size: 1
2010-01-30 20:34:37,211 DEBUG [org.hibernate.jdbc.AbstractBatcher] (http-0.0.0.0-8080-2) about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2010-01-30 20:34:37,215 DEBUG [org.hibernate.transaction.JDBCTransaction] (http-0.0.0.0-8080-2) committed JDBC Connection

You can see in the log, that the debug here says that it should be store_id 1 and brand_id 9, but in the debug statements around this, and when it actually does the insert, it reverses these, and inserts it as store_id 9 and brand_id 1.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list