Posts

Showing posts with the label HIbernate

MSSQL server audit

MSSQL Server Auditing on AWS RDS Enable MSSQL Server Auditing on AWS RDS To enable MSSQL server auditing on AWS RDS, please follow these steps: Login to AWS console and go to RDS. Create an option group under RDS > Option groups Give name as 'SqlServerAudit' Provide description as 'Option group for SQL Server audit' Choose the engine as same as the one used while creating the database in RDS. Choose the latest engine version. Save. Go to RDS > Option groups and select the radio button on the option group you just created Click on Add Option. Select SQLSERVER_AUDIT under “Option name” Choose the S3 bucket name where you want to keep the audit files once they grow more than the specified limit. Choose the appropriate IAM role with write access to the S3 bucket. Scheduling > Immediately and then click on “Add Option“....

Hibernate inserts duplicate child on cascade

At times we all use hibernate's cascade feature to cascade the child entries into database for OneToMany and ManyToMany relationships. If it is a first entry in DB then everything works fine but when we want to update the number/quantity of child of an existing parent, hibernate adds duplicate children. Assume the parent already exists with few children. Below is the relationship: Parent Mapping for OneToMany with Child: @OneToMany(targetEntity = ChildrenImpl.class, mappedBy = "parent", orphanRemoval = true, fetch = FetchType.LAZY) @Cascade(value = CascadeType.ALL) private List<Children> children = new ArrayList<Children>(); Child Mapping with parent ManyToOne @ManyToOne(targetEntity = ParentImpl.class, fetch = FetchType.LAZY) @JoinColumn(name = "PARENT_ID") private Parent parent; Below is the code which leads to duplicate children. Children newChild = new ChildrenImpl(); newChild.setName("I am a new child"); /* More setters here *...