My mistake, I've just looked at the code and WithForeignKey is for setting the actual constraint name, so that's my point out of the window. I'm guessing now it's a conflict between your composite-id and references, are you able to test the behavior if you use a regular identity over a composite one? This is all a bit trial-and-error, I know... :)
On Mon, Mar 23, 2009 at 1:14 PM, Bill <agilemeis...@gmail.com> wrote: > > Thanks James! > > This is an interesting problem. I can see the similarities to what I > have except that Derik's example is with a property... for mine it is > an identifier. If I remove the .WithColumns("ProjectID") then it > generates it's own column name like this: > > <many-to-one cascade="all" name="Project" column="Project_id" /> > <bag name="lstRouteLocation" table="RouteLocation"> > <key foreign-key="RouteID"> > <column name="ProjectID" /> > <column name="RouteID" /> > </key> > <one-to-many class="vRA.Domain.RouteLocationNH, vRA, > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> > </bag> > > This fails since it can't find that name: > > NHibernate.Exceptions.GenericADOException: could not insert: > [vRA.Domain.RouteObjNH][SQL: INSERT INTO Route (MilesTraveled, > VehicleId, SlackTime, StartTime, Project_id, ProjectID, RouteID) > VALUES (?, ?, ?, ?, ?, ?, ?)] ---> > System.Data.SqlClient.SqlException: Invalid column name 'Project_id'.. > > Interesting. > > Thanks! > Bill > > On Mar 23, 7:55 am, James Gregory <jagregory....@gmail.com> wrote: > > Sorry Bill, I was out last night and missed your last message. Derik > > Whittaker actually blogged very > > recently< > http://devlicio.us/blogs/derik_whittaker/archive/2009/03/19/nhibernat.. > .>on > > your exact error message. It's basically saying you're mapping a > > column > > twice. Which in your case, is probably in this line: > > References(x => x.Project).Cascade.All() > > .WithForeignKey("ProjectID").WithColumns("ProjectID"); > > > > The WithForeignKey sets the foreign-key column, while the WithColumns > sets > > any additional colums. So you're essentially telling NHibernate that your > > relationship is made up of two columns (a composite reference), but > giving > > it the same column twice. I'd suggest trying to remove the WithColumns > and > > see what happens. > > > > > > > > On Mon, Mar 23, 2009 at 2:37 AM, Bill <agilemeis...@gmail.com> wrote: > > > > > I tried a bunch of things but really don't have a clue what that error > > > I am getting means. Maybe if I could see an example of using a HasMany > > > and then the Reference back with the PersistenceSpecification I could > > > make some sense of it. Not sure what else I might try. Any suggestions > > > would be appreciated. > > > > > thanks, > > > Bill > > > > > On Mar 22, 2:59 pm, Bill <agilemeis...@gmail.com> wrote: > > > > I set Cacasde.All() on the Reference like this: > > > > > > // Reference back to parent Project > > > > References(x => x.Project).Cascade.All() > > > > > .WithForeignKey("ProjectID").WithColumns("ProjectID"); > > > > > > I get the same error > > > > > > System.IndexOutOfRangeException: Invalid index 6 for this > > > > SqlParameterCollection with Count=6.. > > > > > > Its creating the Project row in the database from the test. > > > > > > Here's my class map file > > > > > > public class RouteObjMap : ClassMap<RouteObjNH> > > > > { > > > > public RouteObjMap() > > > > { > > > > WithTable("Route"); > > > > UseCompositeId() > > > > .WithKeyProperty(x => x.ProjectID) > > > > .WithKeyProperty(x => x.RouteID); > > > > > > Map(x => x.StartTime); > > > > Map(x => x.SlackTime); > > > > Map(x => x.VehicleId); > > > > Map(x => x.MilesTraveled); > > > > > > // Reference back to parent Project > > > > References(x => x.Project).Cascade.All() > > > > > .WithForeignKey("ProjectID").WithColumns("ProjectID"); > > > > > > // Child List of Route Locations > > > > HasMany(x => x.lstRouteLocation) > > > > .WithTableName("RouteLocation") > > > > .WithForeignKeyConstraintName("ProjectID") > > > > .WithForeignKeyConstraintName("RouteID") > > > > .KeyColumnNames.Add("ProjectID", "RouteID"); > > > > } > > > > > > And my test > > > > > > public void VerifyRouteObjSaves() > > > > { > > > > DateTime dt = new DateTime(2009, 3, 20); > > > > var repository = new NHibernateRepository<RouteObjNH> > > > > (UnitOfWorkFactoryInstance, vRADatabase.Default); > > > > using (var transaction = > > > > UnitOfWorkFactoryInstance.GetSession(vRADatabase.Default)) > > > > { > > > > ISessionBuilder sessionBuilder = new > SessionBuilder > > > > (); > > > > ISession session = sessionBuilder.GetSession > > > > (vRADatabase.Default); > > > > > > new PersistenceSpecification<RouteObjNH>(session) > > > > .CheckProperty(x => x.ProjectID, "12345") > > > > .CheckProperty(x => x.RouteID, "R00001") > > > > .CheckProperty(x => x.StartTime, dt) > > > > .CheckProperty(x => x.SlackTime, 420) > > > > .CheckProperty(x => x.VehicleId, "53LTL") > > > > .CheckProperty(x => x.MilesTraveled, 34) > > > > .CheckReference(x => x.Project, _project) > > > > .VerifyTheMappings(); > > > > } > > > > > > thanks! > > > > Bill > > > > > > On Mar 22, 2:42 pm, James Gregory <jagregory....@gmail.com> wrote: > > > > > > > Hmm, try setting a Cascade on that relationship. > > > > > > > On Sun, Mar 22, 2009 at 6:38 PM, Bill <agilemeis...@gmail.com> > wrote: > > > > > > > > Hi, > > > > > > > > I'm new to FNH and NH and have made some progress with getting my > > > > > > classes mapped using Fluent. Then I found the > > > > > > PersistenceSpecification. My question is that when I am just > checking > > > > > > against the properties of my class I seem to get the results I > > > expect. > > > > > > If my mapping class has a Reference back to the parent, I seem to > get > > > > > > the error: > > > > > > > > NHibernate.TransientObjectException: object references an unsaved > > > > > > transient instance - save the transient instance before flushing: > > > > > > vRA.Domain.Project. > > > > > > > > If I remove the > > > > > > > > References(x => x.Project) > > > > > > > .WithForeignKey("ProjectID").WithColumns("ProjectID"); > > > > > > > > from my mapping file - all is well. > > > > > > > > If add the References back into my map file and then add a > > > > > > > > .CheckReference(x => x.Project, _project) > > > > > > > > in my PersistenceSpecification I get this error - which I can't > quite > > > > > > decipher > > > > > > > > System.IndexOutOfRangeException: Invalid index 6 for this > > > > > > SqlParameterCollection with Count=6.. > > > > > > > > I'm probably just doing something stupid. Any ideas would be > > > > > > gratefully welcomed. > > > > > > > > thanks! > > > > > > Bill- Hide quoted text - > > > > > > > - Show quoted text -- Hide quoted text - > > > > > > - Show quoted text -- Hide quoted text - > > > > - Show quoted text - > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to fluent-nhibernate@googlegroups.com To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---