NHibernate problem - Get works but save doesn't RRS feed

  • Question

  • User1316454812 posted


    I'm trying to map to database one object of type Offence. Objects contains other objects of type OffenceStatus and OffenceType. This object are already in the database, user can't add new ones, so I don't need to save them. When I manually insert some data into Offence table and try to get it in application, it works fine. But when I try to save new object type offence it says that it can't insert null into column OffenceStatusId. I checked and OffenceStatus is not null.

    I have the following code

      public OffenceMap()
                Id(x => x.OffenceId).GeneratedBy.Identity();
                Map(x => x.EquipmentId).Nullable().Length(50);
               [b] References(x => x.OffenceStatus, "OffenceStatusId").PropertyRef("OffenceStatusId");
                References(x => x.OffenceType, "OffenceTypeId");[/b]
                Map(x => x.OffenceDate).CustomSqlType("DateTime").Not.Nullable();
                Map(x => x.OffenceTime).CustomSqlType("DateTime").Not.Nullable();
                References(x => x.Vehicle, "VehicleLicensePlateNumber");
                Map(x => x.IsArchived);
               Map(x => x.MarkedForPrinting, "IsMarkedForPrinting");

    public void AddOffence(DateTime ofdate, DateTime oftime, string eqid, string licplatenum, int offtype)
                OffenceTypeRepository otr = OffenceTypeRepository.GetInstance();
                OffenceType ot = otr.GetOffenceTypeById(offtype);

                OffenceStatusRepository osr = OffenceStatusRepository.GetInstance();
                OffenceStatus os = osr.GetOffenceStatusById((int)OffenceStatusName.New);

                Vehicle veh = VehicleRepository.GetInstance().GetVehicleByLicensePlateNum(licplatenum);

                Offence newOffence = new Offence(ot, ofdate, oftime, veh, os,eqid);

    I tried everything i could think of. Please help!

    Sunday, June 6, 2010 10:58 AM

All replies