unit testing - Fluent NHibernate PersistenceSpecification not-null property references a null or transient value error -


i've been struggling mess days now, trying figure out exact reason error. 1 word, failure! have been trying unit test classmap i've written reference references reference.

    [testmethod]     public void issuereturnregistermap_create_success()     {         var maxdifference = timespan.frommilliseconds(990);         booksize sz = new booksize() { id = "1", name = "a" };         department dpt = new department() { id = "1", name = "philosophy" };         author auth = new author() { id = "2", firstname = "wise", lastname = "person" };         publisher pub = new publisher() { id = "1", name = "pub1", address = "address 1" };         language lang = new language() { id = "1", name = "lang1" };         patron ptrn = new patron()         {             id = "1",             firstname = "first",             lastname = "last",             age = 82,             address = "address1",             gender = "male",             occupation = "occupation1",             telephone1 = "01234567890",             telephone2 = "01234567890"         };          book book = new book()         {             id = "1",             name = "book1",             number = "12",             booksize = sz,             department = dpt,             author = auth,             commentator = "another wiseman",             publisher = pub,             language = lang,         };         member member = new member()         {             id = "1",             patron = ptrn,             isregistered = true         };          //edit: acc. firo's suggestion         database.session.save( sz );         database.session.save( dpt );         database.session.save( auth );         database.session.save( lang );         database.session.save( pub );         database.session.save( ptrn );         database.session.save( book ); //@firo: throws same exception here! :-(         database.session.save( member );          new persistencespecification<issuereturnentry>( database.session, new customequalitycomparer() )         .checkproperty( x => x.id, "1" )         .checkreference( x=> x.book, book )         .checkreference( x => x.member, member )         .checkproperty( x => x.issuedby, "librarian" )         .checkproperty( x => x.issuedate, datetime.now, new datetimeequalitycomparer( maxdifference ) )         .checkproperty( x => x.duedate, datetime.now, new datetimeequalitycomparer( maxdifference ) )         .checkproperty( x => x.returndate, datetime.now, new datetimeequalitycomparer( maxdifference ) )         .checkproperty( x => x.returnby, "user" )         .verifythemappings();     } 

as can see book made of references booksize, department etc. , book becomes references issuereturnregister map. same goes member. throws 'not-null property references null or transient value error' exception booksize object. appreciated. in advance.

the error means booksize referenced entity stored not stored , can not stored in action because cascading disabled.

so either do

  • references(x => x.booksize).cascade.all() in mapping or
  • database.session.save(bz) before running persistencespecification

same other referenced entities

update: persistent entities should have equals method taking id account

public override bool equals(object obj) {     var other = obj booksize;     return other != null && (id == 0) ? referenceequals(this, other) : id == other.id; }  private int? _hashcode; public override int gethashcode() {     return _hashcode.hasvalue ? _hashcode.value : _hashcode = id; } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -