LOL.. well... in some place you are creating a new User then you are assigning it a Title. That Title should be a persistent entity coming from a NHibernate query, if the title should exists. Where you are assigning a new Title you have to persist it (session.Save) before persist the User or you have to specify the cascading action in the mapping (cascade="save-update,persist")
-- Fabio Maulo El 05/12/2010, a las 05:53, megaman <[email protected]> escribió: > here is the classes: > > public class User > { > private int Key; > private string name; > private Title title; > > public Spender() > { > > name = string.Empty; > title = null; > } > > public Spender(Spender spender) > { > key = spender.Key > name = spender.Name; > title = spender.Title; > } > > public virtual int Key > { > get { return key; } > set { name = key; } > } > > public virtual string Name > { > get { return name; } > set { name = value; } > } > > public virtual Title Title > { > get { return title; } > set { title = value; } > } > } > > and title class is: > pubic class Title > { > private int key; > private string name; > > public Title() > { > name = ""; > } > > public Title( Title title ) { > key = title.Key; > description = title.Description; > } > > public virtual int Key > { > get { return key; } > set { name = value; } > } > > public virtual Title Title > { > get { return title; } > set { title = value; } > } > > > } > > The way how i save that is like defined in the book, i mean > i have the class UserModel; > > [PersistenceConversational( > MethodsIncludeMode = MethodsIncludeMode.Implicit)] > public class UserModel : IUserModel > { > private readonly IDao<User> _userDAO; > > public virtual void Save(User user) > { > _userDAO.Save(user); > } > > > } > The implementation of DAO and DaoImp ist just like this found in the > book in chapter 3 pages (94,95,96) > Thanks again Fabio > On 5 Dez., 01:18, Fabio Maulo <[email protected]> wrote: >> Can we see your classes and what you are doing to persist a User ? >> >> -- >> Fabio Maulo >> >> El 04/12/2010, a las 20:48, megaman <[email protected]> >> escribió: >> >> yes: >> User mapping-File: >> <class name="Spender" table="user" lazy="false" > >> <id name="Key" column="user_id" type="Int32" > >> <generator class="identity" /> >> </id> >> <many-to-one >> name="Title" >> column="TITLE_ID" >> class="Title" >> not-found="ignore" /> >> </class> >> >> Title mapping-File: >> <class name="Title" table="TITLE"> >> <id name="Key" column="TITLE_ID" type="Int32" > >> <generator class="identity" /> >> </id> >> >> <property name="Name" type="String" > >> <column name="DESCRIPTION" /> >> </property> >> </class> >> >> On 5 Dez., 00:21, Fabio Maulo <[email protected]> wrote: >> >> advise: switch your mind. >> >> When you are working with a tool as NHibernate you have to talk about >> >> entities, components (aka valueObjects), with properties and relations >> >> between classes. >> >> Can we see your classes and what you are doing to persist a User ? >> >> On Sat, Dec 4, 2010 at 6:32 PM, megaman <[email protected] >> >>> wrote: >> >> Hi Jason, >> >> glad to hear from you and thank you for the book, great tips >> >> there ;-). >> >> So the problem is why nhibernate try to update the title table. This >> >> is an unidirectional many-one relationship. >> >> I just wanna update the table user, i mean the entity user has a >> >> reference to the entity title thats clear but in the db the table >> >> user >> >> has only the fk titleId. >> >> Please i need you help and thanks again. >> >> On 4 Dez., 21:46, Jason Dentler <[email protected]> wrote: >> >> The instructions in the exception message are clear. Title is transient, >> >> and >> >> it is referenced in the graph of objects to be saved. You must explicitly >> >> save the title before flushing -or- use a cascade option that will do >> >> this >> >> for you automatically. >> >> Thanks, >> >> Jason >> >> On Sat, Dec 4, 2010 at 10:56 AM, megaman < >> >> [email protected]>wrote: >> >> hi everyone, >> >> i have already set the cascade to none but when i save the user , i >> >> always get the exception object references an unsaved transient >> >> instance - save the transient instance before flushing. maybe i have >> >> to disable the auto dirty checking option? i am using the cbpt pattern >> >> to deal with multiple sessions management. >> >> Guys i need some help here. >> >> Thanks in advance >> >> On 4 Dez., 17:53, megaman <[email protected]> wrote: >> >> hi everyone, >> >> i implemented the tip of the book "nhibernate 3 cookbook" >> >> concerning "CbpT" pattern. In my modell i have an unidirectional >> >> many- >> >> to-one association in the child. Here is the example: >> >> Title >> >> ----- >> >> TitleId >> >> Description >> >> User >> >> ----- >> >> UserId >> >> TitleId >> >> The class user has a reference to the object Title because i want to >> >> display in my gui the description. So user has a unidirectional >> >> many- >> >> to-one association with the table Title. >> >> if i save the User say Session.save( User ) and ten call SaveAll() >> >> which flush the session, i get the exception "save transient entity >> >> Title" and dont get that because the cascade option is set to none. >> >> The definition of this association in the user mapping file is: >> >> many-to-one >> >> name="Title" >> >> column="TitleId" >> >> class="Title" >> >> cascade="none" >> >> not-found="ignore" >> >> Thanks in advance >> >> -- >> >> You received this message because you are subscribed to the Google >> >> Groups >> >> "nhusers" group. >> >> To post to this group, send email to [email protected]. >> >> To unsubscribe from this group, send email to >> >> [email protected]<nhusers%[email protected]<nhusers%[email protected]> >> >> >> >> <nhusers%[email protected]<nhusers%[email protected]> >> <nhusers%[email protected]<nhusers%[email protected]> >> >> >> >> . >> >> For more options, visit this group at >> >> http://groups.google.com/group/nhusers?hl=en. >> >> -- >> >> You received this message because you are subscribed to the Google Groups >> >> "nhusers" group. >> >> To post to this group, send email to [email protected]. >> >> To unsubscribe from this group, send email to >> >> [email protected]<nhusers%[email protected]<nhusers%[email protected]> >> >> >> >> . >> >> For more options, visit this group at >> >> http://groups.google.com/group/nhusers?hl=en. >> >> -- >> >> Fabio Maulo >> >> -- >> You received this message because you are subscribed to the Google Groups >> "nhusers" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group >> athttp://groups.google.com/group/nhusers?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
