and I guess that is exactly my question.... how come?
I am saving the object using save(). The generator whichever I use does seem to work. Loading works by the way. I just fixed the sequence of save(), flush() and commit(), thank you. And still no cigar.
Oh yes, I am implementing Lifecycle...and yes I just RFM on Lifecycle... but I still don't see why that would matter.... HELP!?
Here is the class:
Code:
public class InventoryItem implements Lifecycle {
private long id = -1;
private String partNo = "";
private String name = "";
....
Here is the mapping:Code:
<hibernate-mapping>
<class
name="inventory.InventoryItem"
table="inventory_item">
<id name="ID"
column="inventory_item_id"
type="long"
unsaved-value="-1">
<generator class="database.IdGenerator">
<param name="table">inventory_item</param>
</generator>
</id>
<property
name="partNo"
type="java.lang.String"
update="true"
insert="true"
column="part_no"
/>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>
....
Here is the TestCaseCode:
public class InventoryItemTest extends TestCase implements TestConstants {
Session session;
public InventoryItemTest(String name)
{
super(name);
}
public void setUp() throws Exception
{
try {
SessionFactory sessionFactory =
HibernateSesssionFactoryManager.getFactory();
session = sessionFactory.openSession();
} catch (Exception e) {
Logger.error(getClass(), e);
}
}
public void tearDown() throws Exception
{
session.close();
}
[color=green] public void testWriteNew() throws Exception {
InventoryItem item = new InventoryItem();
item.setSystemID(TEST_SYSTEM_ID);
item.setCategory("Carpentry");
item.setName("Hammer");
session.save(item);
session.flush();
session.connection().commit();
}[/color]
}
Here is what is logged starting with the save():
2003-12-16 09:39:46,078 DEBUG main net.sf.hibernate.impl.SessionImpl - opened session
2003-12-16 09:39:47,596 DEBUG main net.sf.hibernate.impl.SessionImpl - saving [inventory.InventoryItem#74]2003-12-16 09:39:47,803 DEBUG main net.sf.hibernate.impl.SessionImpl - flushing session
2003-12-16 09:39:47,806 DEBUG main net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections
2003-12-16 09:39:47,821 DEBUG main net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections
2003-12-16 09:39:47,824 DEBUG main net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates
2003-12-16 09:39:47,827 DEBUG main net.sf.hibernate.impl.SessionImpl - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
2003-12-16 09:39:47,830 DEBUG main net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2003-12-16 09:39:47,833 DEBUG main net.sf.hibernate.impl.SessionImpl - executing flush
2003-12-16 09:39:47,835 DEBUG main net.sf.hibernate.impl.SessionImpl - post flush
2003-12-16 09:39:47,837 DEBUG main net.sf.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
2003-12-16 09:39:47,840 DEBUG main net.sf.hibernate.connection.DriverManagerConnectionProvider - using pooled JDBC connection, pool size: 0
2003-12-16 09:39:47,844 DEBUG main net.sf.hibernate.impl.SessionImpl - closing session
2003-12-16 09:39:47,846 DEBUG main net.sf.hibernate.impl.SessionImpl - disconnecting session
2003-12-16 09:39:47,850 DEBUG main net.sf.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
2003-12-16 09:39:47,853 DEBUG main net.sf.hibernate.impl.SessionImpl - transaction completion
[/code]