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 7435315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:03:16+00:00 2026-05-29T10:03:16+00:00

I would like to delete all rows in tbl_license_user_alert when deleting either a license

  • 0

I would like to delete all rows in tbl_license_user_alert when deleting either a license or an user: http://www.img-teufel.de/uploads/Unbenannt1d4f8a349jpg.jpg

Where do I need to set the cascade stuff?

Cascade Attribute or @Cascade Annotation?

Which CascadeStyle do I need for this purpose?

@Entity
@Table( name = "tbl_license" )
public class License implements Serializable
{
  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue
  @Column( name = "id", nullable = false, columnDefinition = "serial" )
  private int id;

  @OneToMany( fetch = FetchType.LAZY, mappedBy = "id.license" )
  private List<LicenseUserAlert> alerts;

  // getter + setter
}

@Entity
@Table( name = "tbl_license_user_alert" )
@AssociationOverrides({
  @AssociationOverride( name = "id.user", joinColumns = @JoinColumn( name = "user_id", columnDefinition = "int" ) ),
  @AssociationOverride( name = "id.license", joinColumns = @JoinColumn( name = "license_id", columnDefinition = "int" ) )
})
public class LicenseUserAlert implements Serializable
{
  private static final long serialVersionUID = 1L;

  @EmbeddedId
  private LicenseUserAlertId id;

  @Column( name = "timer", columnDefinition = "int default 86400" )
  private int timer = 86400;

  public LicenseUserAlertId getId()
  {
    return id;
  }

  public void setId( LicenseUserAlertId id )
  {
    this.id = id;
  }

  @Transient
  public License getLicense()
  {
    return id.getLicense();
  }

  public void setLicense( License license )
  {
    id.setLicense( license );
  }

  @Transient
  public User getUser()
  {
    return id.getUser();
  }

  public void setUser( User user )
  {
    id.setUser( user );
  }

  public int getTimer()
  {
    return timer;
  }

  public void setTimer( int timer )
  {
    this.timer = timer;
  }
}

@Embeddable
public class LicenseUserAlertId implements Serializable
{
  private static final long serialVersionUID = 1L;

  @ManyToOne
  @ForeignKey( name = "tbl_license_fkey" )
  private License license;

  @ManyToOne
  @ForeignKey( name = "tbl_user_fkey" )
  private User user;

  public LicenseUserAlertId( License license, User user )
  {
    this.license = license;
    this.user = user;
  }

  public LicenseUserAlertId()
  {
  }

  public License getLicense()
  {
    return license;
  }

  public void setLicense( License license )
  {
    this.license = license;
  }

  public User getUser()
  {
    return user;
  }

  public void setUser( User user )
  {
    this.user = user;
  }
}
  • 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-29T10:03:17+00:00Added an answer on May 29, 2026 at 10:03 am

    try to add following annotations to your License.alerts if you are working with JPA.

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "id.license", cascade = { CascadeType.REMOVE }, orphanRemoval = true)
    private List<LicenseUserAlert> alerts;
    

    EDIT

    orphanRemoval is from jpa2.0. OneToMany annotation. (javax.persistence.OneToMany)

    if you don’t have jpa2.0, then you can complement jpa cascading by hibernate cascade annotation.:

    @OneToMany( .... cascade = {CascadeType.REMOVE} )
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private List<LicenseUserAlert> alerts;
    

    infact this cascadeType is deprecated in later hibernate version. see source code from Hibernate 3.6.8:

    /** @deprecated use @OneToOne(orphanRemoval=true) or @OneToMany(orphanRemoval=true) */
        @Deprecated DELETE_ORPHAN,
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to delete all the rows found by that query: SELECT cart_abandon.*
I would like to delete all rows from table A that are not exist
I would like to delete all the links in a quicklaunch in SP2010 with
I would like to delete all elements from an array that don't meet some
If a user inserts rows into a table, i would like SQL Server to
I have two tables A and B. I would like to delete all the
I would like to implement a swipe gesture to delete rows in a ListView
I would like to delete the space between lines in a text file using
I would like to delete every double space in a file open in vim,
We have an application that logs using log4net. But we would like to delete

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.