Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3481110
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:24:55+00:00 2026-05-18T10:24:55+00:00

my application has 2 entities called Event and Transaction. An Event may or may

  • 0

my application has 2 entities called Event and Transaction. An Event may or may not have a transaction but can only have 1 Transaction. I thought the best way to map this was with a HasOne mapping. So far everything is fine but i want to make sure that when you delete an Event it won’t delete it if has a Transaction.

Normally on a HasMany relationship i would just set an Inverse and change Cascade to None. While Cascade exists, Inverse doesn’t and the event deletes regardless of whether it has a Transaction or not.

I’d appreciate it if someone could show me the correct way of doing this. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:24:56+00:00Added an answer on May 18, 2026 at 10:24 am

    You could always create your own custom delete behaviour using a DeleteEventListener:

    public class DeleteEventListener : DefaultDeleteEventListener
      {
        protected override void DeleteEntity(IEventSource session, object entity, EntityEntry entityEntry, bool isCascadeDeleteEnabled, IEntityPersister persister, ISet transientEntities)
        {
          Event event = entity as Event;
          if (event != null && event.Transaction != null) throw new Exception("You can't delete this Event! Look! It has a Transaction!");
          CascadeBeforeDelete(session, persister, entity, entityEntry, transientEntities);
          CascadeAfterDelete(session, persister, entity, transientEntities);
        }
      }
    

    This DeleteEventListener would then need to be registered as part of your NHibernate setup configuration. Within the session factory element:

    <event type="delete">
    <listener class="myNamespaces.DeleteEventListener, myAssembly" />
    </event> 
    

    I haven’t tested this particular code but I have similar code in my app so I can help out if you get stuck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application has one activity which starts two services but does not bind them.
I have an ASP.Net application which has an area called 'Customers'. This area has
I have an existing application that has the following entities in the database Customer
My web application has got a lot of service tables/entities, such as payment_methods ,
My application has multiple SQLite tables(around 20 with different fields). This I have created
My Application has 3 activities (MainActivity,SampleActivity,TempActivity) and Application have to start from MainActivity because
The application has been put in iCloud since the beginning, so I have the
One of my entities Machinery has got a String property called notes . JPA
I have an application in mind which dicates database tables be append-only; that is,
I am writing a java simulation application which has a lot of entities to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.