asp.net mvc - NHibernte CreateAlias for 2 multiply class -
i have 3 classes: book, genre, authors
public class book { public virtual int id { get; set; } public virtual string name { get; set; } public virtual string description { get; set; } public virtual int mfraiting { get; set; } public virtual int pagenumber { get; set; } public virtual ilist<genre> genres { get; set; } public virtual series series { get; set; } public virtual mind mind { get; set; } public virtual ilist<author> authors { get; set; } public book() { genres = new list<genre>(); authors = new list<author>(); } } public class genre { public virtual int id { get; set; } public virtual string name { get; set; } public virtual ilist<book> books { get; set; } public genre() { books=new list<book>(); } } public class author { public virtual int id { get; set; } public virtual string name { get; set; } public virtual string surname { get; set; } public virtual string biography { get; set; } public virtual ilist<book> books { get; set; } public author() { books=new list<book>(); } }
and classmaps
public class bookmap : classmap<book> { public bookmap() { id(x => x.id); map(x => x.name); hasmanytomany(x => x.genres) .cascade.all() .table("book_genre"); hasmanytomany(x => x.authors) .cascade.all() .table("book_author"); references(x => x.series); hasone(x => x.mind).constrained(); } } public class genremap : classmap<genre> { public genremap() { id(x => x.id); map(x => x.name); hasmanytomany(x => x.books) .cascade.all() .inverse() .table("book_genre"); } } public class authormap : classmap<author> { public authormap() { id(x => x.id); map(x => x.name); map(x => x.surname); map(x => x.biography); hasmanytomany(x => x.books) .cascade.all() .inverse() .table("book_author"); } }
when try write in code var criteria = session.createcriteria(); criteria.createalias("genres", "genre", jointype.leftouterjoin); works well, when so
public actionresult index() { var criteria = session.createcriteria<book>(); criteria.createalias("genres", "genre", jointype.leftouterjoin); criteria.createalias("authors", "author", jointype.leftouterjoin); criteria.setresulttransformer(new distinctrootentityresulttransformer()); }
i see exception cannot simultaneously fetch multiple bags. how can result of criteria?
thank
i resolve problem! replace ilist on iset, , replace new list<"class"> on new hashset<"class">
i read problem here. http://developer-should-know.tumblr.com/post/118012584847/jpa-fetching-strategies 1 collection fetched using join strategy can of type list, other collection must of type set. otherwise exception thrown:
hibernateexception: cannot simultaneously fetch multiple bags
Comments
Post a Comment