-->
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.  [ 3 posts ] 
Author Message
 Post subject: got org.hibernate.action.DelayedPostInsertIdentifier error
PostPosted: Sat Mar 22, 2008 9:22 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 30, 2008 8:34 am 
Newbie

Joined: Wed May 14, 2008 8:36 am
Posts: 6
i had the same problem initially, but calling save/merge after starting a transaction solved the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 9:48 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Calling save or merge after starting the transaction will ensure that any transient or detached objects become associated with the Hiberante Session, and become 'persistent' objects. Thus, if you use the save or merge methods, you can avoid this particular problem.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.