Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

one to many - Hibernate insert cascade not inserting foreign key -


i have 2 entities:

@entity public class file ....... @id @generatedvalue(strategy=generationtype.auto) private int id; @onetomany(fetch=fetchtype.lazy, mappedby="file", cascade=cascadetype.all) private list<tag> tags; ....... other properties .......  @entity public class tag ....... @id @generatedvalue(strategy=generationtype.auto) private int id; @manytoone @joincolumn(name="file_id") private file file; @column private string tag; ....... other properties ....... 

i trying insert file (and subsequently tag) doing following:

file file = new file(); tag tag = new tag(); tag.settag("tag1"); tag2 tag2 = new tag(); tag2.settag("tag2"); list<tag> tags = new arraylist<tag>(); tags.add(tag); tags.add(tag2); file.settags(tags); ---add other file attributes here--- 

i inserting file in dao using:

sessionfactory.getcurrentsession().saveorupdate(file);  

in logs see insert "file" table , 2 inserts tag table, however, foreign key in tag table points file table (file_id) null.

what possibly doing wrong?

you not setting file tag, tag's file. remember in oop, opposed relational model, have set both ends of relationship. can't navigate tag file because added set of tags file. in case, can navigate file tag (ie: list tags file). can't tell file tag belongs to, looking @ tag.

what done helper method in 1 of models, this:

public void addtag(tag tag) {   this.tags.add(tag);   tag.setfile(this); } 

see this example (from hibernate's test suite):


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -