-->
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: Get works fine but save doesn't
PostPosted: Sat Jun 05, 2010 5:01 am 
Newbie

Joined: Sat Jun 05, 2010 4:50 am
Posts: 1
Hi!

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

Code:
  public OffenceMap()
        {
        Not.LazyLoad();
            Table("Offence");
            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);
            try
            {
                _NHibernateOffenceRep.Save(newOffence);
                _NHibernateOffenceRep.Commit();
                _AllOffences.Add(newOffence);
            }
            catch
            {
                _NHibernateOffenceRep.HandleError();
            }
        }


I tried everything i could think of. Please help!
Thanks!


Top
 Profile  
 
 Post subject: Re: Get works fine but save doesn't
PostPosted: Mon Jun 07, 2010 4:49 am 
Newbie

Joined: Mon Jun 07, 2010 4:46 am
Posts: 1
thumps up for your article, great post...

_________________
ugg shoes uggs for Cheap uggs outlet


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.