Hi, So, I'm trying to understand - this is an issue with PersistenceSpecification or Fluent NHibernate, not a problem with NHibernate itself, correct? My complete entity heirarchy seems to be working in my application - I just can't figure out how to use PersistenceSpecification to test it.
thanks! Bill On Mar 23, 2:09 pm, Bill <agilemeis...@gmail.com> wrote: > Thanks again James. I really appreciate all you're doing to try and > help. I understand the trial and error part. :) > > I tried using a single ID instead of the composite and get the same > error. But from what Derik said, it looks like I am still using the > ProjectID key in both places. Here's my latest map file: > > public class RouteObjMap : ClassMap<RouteObjNH> > { > public RouteObjMap() > { > WithTable("Route"); > > Id(x => x.ProjectID); > Map(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"); > } > } > > Here's the XML > > <?xml version="1.0" encoding="utf-8"?> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="vRA, > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" > namespace="vRA.Domain"> > <class name="RouteObjNH" table="Route" xmlns="urn:nhibernate- > mapping-2.2"> > <id name="ProjectID" type="String" column="ProjectID"> > <generator class="assigned" /> > </id> > <property name="RouteID" type="String"> > <column name="RouteID" /> > </property> > <property name="VehicleId" type="String"> > <column name="VehicleId" /> > </property> > <property name="StartTime" type="DateTime"> > <column name="StartTime" /> > </property> > <property name="SlackTime" type="Int32"> > <column name="SlackTime" /> > </property> > <property name="MilesTraveled" type="Int32"> > <column name="MilesTraveled" /> > </property> > <many-to-one cascade="all" foreign-key="ProjectID" name="Project"> > <column name="ProjectID" /> > </many-to-one> > </class> > </hibernate-mapping> > > The way that I had my mapping files previously let me get the entire > heirarchy of classes starting at the Project class level. It's just > that the PersistenceSpecificaion didn't seem to work to valid them. > > I'm still getting the same error: > > System.IndexOutOfRangeException: Invalid index 6 for this > SqlParameterCollection with Count=6.. > > Here is my test: > > private Project _project = new Project() { > ProjectID = "12345", > UserID = "PL\\600124238", > MachineName = "GCR1MG1", > NodeType = 1, > FullPath = "/AllProjects/", > FlagSelected = 1, > SequenceNo = 0, > TimeCreated = dt > }; > > [TestMethod] > public void VerifyRouteObjSaves() > { > DateTime dt = new DateTime(2009, 3, 20); > > ISessionBuilder sessionBuilder = new SessionBuilder(); > ISession session = sessionBuilder.GetSession > (vRADatabase.Default); > > new PersistenceSpecification<RouteObjNH>(session) > .CheckProperty(x => x.ProjectID, "23456") > .CheckProperty(x => x.RouteID, "R00001") > .CheckProperty(x => x.StartTime, dt) > .CheckReference(x => x.Project, _project) > .VerifyTheMappings(); > } > > thanks!! > Bill > > On Mar 23, 9:36 am, James Gregory <jagregory....@gmail.com> wrote: > > > > > 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 > > ... > > read more »- 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 -~----------~----~----~----~------~----~------~--~---