-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Why cant it get the id of the child righaway?
PostPosted: Mon Sep 14, 2009 5:45 am 
Newbie

Joined: Mon Sep 14, 2009 4:59 am
Posts: 2
hi
i been strugling with this for 2days now so i thought i would give it a shot here.

my scenario looks like this. i got a Customer and CustomerPhone. Now i save the Customer and CustomerPhone at the same time but the CustomerPhone dont get no Id rightaway. but if i do a redirect to a other site and get the Customer object there the CustomerPhone will have a Id.

my code for the the classes look like this.

Code:
public virtual int Id { get; private set; }
        public virtual string Name { get; set; }
        public virtual string OrgNumber { get; set; }
        public virtual DateTime? CreateDate { get; set; }
        public virtual bool Active { get; set; }
        public virtual string Email { get; set; }

        public virtual IList<CustomerPhone> CustomerPhones { get; set; }
               
        public Customer()
        {
            CustomerPhones = new List<CustomerPhone>();
        }

        public virtual void AddCustomerPhones(CustomerPhone customerPhone)
        {
            customerPhone.Customer = this;
            CustomerPhones.Add(customerPhone);
        }


i do fluent nhibernate on the mapping but i have had it looked at and it dont seem to be the problem.
Quote:
Id(x => x.Id, "Id").GeneratedBy.Identity().WithUnsavedValue(default(int));

Map(x => x.Name);
Map(x => x.CreateDate);
Map(x => x.Active);
Map(x => x.OrgNumber);
Map(x => x.Email);

HasMany<CustomerPhone>(x => x.CustomerPhones).IsInverse().Cascade.All().LazyLoad();


if you got any thoughts on this please write cause this is causing big problems for me.


Top
 Profile  
 
 Post subject: Re: Why cant it get the id of the child righaway?
PostPosted: Tue Sep 15, 2009 7:15 am 
Newbie

Joined: Mon Sep 14, 2009 4:59 am
Posts: 2
the issue was that i had to call the Session.Flush() manually when do the Session.Save()
i had that configured that it do that in the end request..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.