Hi,
After upgrading to Hibernate 3.2.6, I'm running into this problem. I'm not sure if it is due to the upgrade or b/c of some other changes I've made, but I can't seem to get rid of it.
Code:
org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type. Expected: class java.lang.Long, got class org.hibernate.action.DelayedPostInsertIdentifier; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class org.hibernate.action.DelayedPostInsertIdentifier
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:659)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:378)
at org.springframework.orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:769)
at org.appfuse.dao.hibernate.GenericDaoHibernate.save(GenericDaoHibernate.java:81)
at nl.project.dao.PrepareDatabase.fillBids(PrepareDatabase.java:255)
at nl.project.dao.PrepareDatabase.fillDatabase(PrepareDatabase.java:75)
at nl.project.dao.OfferDaoTest.onSetUp(OfferDaoTest.java:37)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:103)
at junit.framework.TestCase.runBare(TestCase.java:132)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
During the execution of the test, I get this error in the console. This is a category object that has a parent relation with itself to function as a tree of categories. I always initialize the children set on instantiation of a Category object. This error only occurs on the second testmethod and all following ones for this unit test, not the first. Probably a different type of error, but I've added it for completeness
org.hibernate.AssertionFailure: collection [nl.project.model.Category.children] was not processed by flush()
at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:205)
at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:333)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:28)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(HibernateTemplate.java:818)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:816)
at org.appfuse.dao.BaseDaoTestCase.flush(BaseDaoTestCase.java:88)
at nl.project.dao.PrepareDatabase.onSetUp(PrepareDatabase.java:133)
at nl.project.dao.OfferDaoTest.onSetUp(OfferDaoTest.java:36)
The relevant piece of code is:
Code:
flush();
List<Offer> offers = offerDao.getOffers(cat, true, OfferType.FORSALE,
0, 10);
int x = 0;
for (Offer myOffer : offers) {
Bid bid = new Bid();
bid.setOffer(myOffer);
bid.setPrice(10.25 + x);
bid.setUser(user1);
user1.addBid(bid);
myOffer.addBid(bid);
myOffer = offerDao.save(myOffer);
user1 = userDao.save(user1);
}
If I save user1 before I save the offer I get save the transient instance before flushing: nl.project.model.Bid
Mappings for the relevant objects
Offer
@OneToMany(cascade=CascadeType.ALL, mappedBy="offer",fetch=FetchType.LAZY)
public Set<Bid> getBids() {
return bids;
}
Bid
@ManyToOne(optional=false, cascade=CascadeType.MERGE)
@JoinColumn(name="FK_UserID", nullable=false)
public Usor getUser() {
return user;
}
@ManyToOne(optional=false, cascade=CascadeType.MERGE)
@JoinColumn(name="FK_OfferID", nullable=false)
public Offer getOffer() {
return offer;
}
User
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="user")
public Set<Bid> getBids() {
return bids;
}
I use
Hibernate 3.2.6
Hibernate Search 3.0.1
hibernate-entitymanager 3.3.2.beta1 (b/c the recent version is not in Maven)
hibernate annotations 3.3.1
Spring 2.5
Appfuse 2.0.1
Any ideas?
Kind regards,
Marc