Fluent-NHibernate mapping configuration cause stackoverflow

27 views
Skip to first unread message

Ezequiel De Luca

unread,
Jan 21, 2021, 9:30:26 AM1/21/21
to nhusers
Hi:

I am having a hard time trying to find out where I am making a mistake on the NHibernate configuration with the following request solution that I am working on. I am trying to achive a relation of one to many between requests and notification (1 request can have several notification send). Below is the information of how I am facing the solution:

Database Tables

    CREATE TABLE tbl_requests
    (
    strID uniqueidentifier NOT NULL,
    objRequestDate datetime NOT NULL,
    objExpirationDate datetime
    ...
    CONSTRAINT pk_request PRIMARY KEY (strID)
    )
    CREATE TABLE tbl_notifications
    (
    strRequest uniqueidentifier NOT NULL,
    objDate datetime NOT NULL
    CONSTRAINT pk_notifiations PRIMARY KEY (strRequest, objDate),
    CONSTRAINT fk_notificationsrequests FOREIGN KEY (strRequest) REFERENCES tbl_requests(strID)
    )

Notification Entity and Mapping

    public class NotificationEntity : IComparable
    {
        public virtual RequestEntity objRequest { get; set; }
        public virtual DateTime objDate { get; set; }
        public int CompareTo(object obj) {...}
    }
    public class NotificationMap : ClassMap<NotificationEntity>
    {
        public NotificationMap()
        {
            Table("tbl_notifications");
            CompositeId()
                .KeyReference(x => x.objRequest, "strRequest")
                .KeyProperty(x => x.objDate, "objDate");
            Not.LazyLoad();
        }
    }

Request Entity and Mapping

    public class RequestEntity
    {
        public virtual Guid strID { get; set; }
    public virtual DateTime objRequestDate { get; set; }
    public virtual DateTime objExpirationDate { get; set; }
        public virtual ISet<NotificationEntity> colNotifications { get; set; }
    }
    public class RequestMap : ClassMap<RequestEntity>
    {
        public RequestMap()
        {
            Table("tbl_requests");
            Id(x => x.strID).GeneratedBy.Guid();
            Map(x => x.objRequestDate);
            Map(x => x.objExpirationDate);
            HasMany<NotificationEntity>(x => x.colNotifications)
                .AsSet()
                .Cascade.All()
                .KeyColumn("strRequest")
                .Fetch.Join()
                .Not.LazyLoad();
            Not.LazyLoad();
        }
    }

Debuging in the console, I find out that when there is an exception with at less one notification send, it starts a loop of the following query (I replace the fields by * just to make it more readable)

NHibernate: SELECT * FROM tbl_requests requestent0_ left outer join
tbl_notifications colnotific7_ on
requestent0_.strID=colnotific7_.strRequest WHERE
requestent0_.strID=@p0;@p0 = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
[Type: Guid (0:0:0)]

NHibernate: SELECT * FROM tbl_requests requestent0_ left outer join
tbl_notifications colnotific7_ on
requestent0_.strID=colnotific7_.strRequest WHERE
requestent0_.strID=@p0;@p0 = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
[Type: Guid (0:0:0)]

...

I guess it is an error on the mapping which cause the loop, do you know what I am doing wrong? I tried replacing the Not.LazyLoad with Lazy ones, but same thing happens.
Reply all
Reply to author
Forward
0 new messages