sipXconfig
Wednesday, March 09, 2005
 
DBUnit seed data, use high primary ids
Using dbunit w/postgres, or any db that uses sequence numbers, is challenging. I just spent half a day finding out why seed data should contain primary keys starting at high numbers, say 1000.

Senario:
1.) create new db
2.) insert a new row with primary key = 1 in dbunit seed file. NOTE: Dbunit does not update sequence numbers. (if this scares you, it should, almost ditched it thinking it was going to be useless, but for some reason I decided this could be worked around)
3.) write a test that adds a new object from db business layer, if this is your first unittest, it will pick primary key = 1 as well and will throw an error. You would think the error would be obvisous, but I didn't "get it" from this hibernate/spring but from lot of debugging:

org.springframework.orm.hibernate.HibernateSystemException:
a different object with the same identifier value was
already associated withthe session: 1,of class:
org.sipfoundry.sipxconfig.phone.LineMetaData; nested
exception is net.sf.hibernate.NonUniqueObjectException:
a different object with the same identifier value was
already associated with the session: 1, of class:
org.sipfoundry.sipxconfig.phone.LineMetaData
net.sf.hibernate.NonUniqueObjectException: a different
object with the same identifier value was already
associated with the session: 1, of class:
org.sipfoundry.sipxconfig.phone.LineMetaData

Comments: Post a Comment

<< Home

Powered by Blogger