Comment:
I can't seem to get a cascading going when I add a transient Bid object into
Item object.
Hibernate version: 2.1
Mapping documents:
Code:
<hibernate-mapping package="com.nyker.test.hibernate">
<class name="Item" table="ITEMS">
<id name="id" column="ITEM_ID" type="long">
<generator class="increment"/>
</id>
<property name="name"/>
<set name="bids" cascade="all">
<key column="ITEM_ID"/>
<one-to-many class="Bid"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.nyker.test.hibernate">
<class name="Bid" table="BIDS">
<id name="id" column="BID_ID" type="long">
<generator class="increment"/>
</id>
<property name="amount"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Code:
Item item = (Item)session.load(Item.class,new Long(1L));
Bid bid1 = new Bid(144.22);
item.getBids().add(bid1);
Full stack trace of any exception that occurs:
Initialize Hibernate ...
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
done.
Hibernate: select item0_.ITEM_ID as ITEM_ID0_, item0_.name as name0_ from ITEMS item0_ where item0_.ITEM_ID=?
Hibernate: select bids0_.ITEM_ID as ITEM_ID__, bids0_.BID_ID as BID_ID__, bids0_.BID_ID as BID_ID0_, bids0_.amount as amount0_ from BIDS bids0_ where bids0_.ITEM_ID=?
Hibernate: update BIDS set amount=? where BID_ID=?
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:127)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2441)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.nyker.test.hibernate.Driver.testOneToManyReinsert(Driver.java:105)
at com.nyker.test.hibernate.Driver.main(Driver.java:110)
Exception in thread "main"
Name and version of the database you are using:
MySQL 4.1
The generated SQL (show_sql=true):
Hibernate: select item0_.ITEM_ID as ITEM_ID0_, item0_.name as name0_ from ITEMS item0_ where item0_.ITEM_ID=?
Hibernate: select bids0_.ITEM_ID as ITEM_ID__, bids0_.BID_ID as BID_ID__, bids0_.BID_ID as BID_ID0_, bids0_.amount as amount0_ from BIDS bids0_ where bids0_.ITEM_ID=?
Hibernate: update BIDS set amount=? where BID_ID=?
Debug level Hibernate log excerpt: