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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:59:04+00:00 2026-05-31T07:59:04+00:00

Have an entity class (Song) with a @OneToMany mapping to another entity (CoverArt), and

  • 0

Have an entity class (Song) with a @OneToMany mapping to another entity (CoverArt), and cascade set to ALL because it seemed easier to just have to save the main entiy and let it take care of persisting the cover art

@Audited
@Entity
public class Song
{
    @Id
    @GeneratedValue
    private Integer recNo;

    @Version
    private int version;

    @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
    private List<CoverArt> coverArts;

    ....

}

But I found at a later point in the code if I just retrieved and instance of the class from the database and then within session modified just one field in the Song entity that would cause it to update all the cover art entities linked to that song even though nothing had changed for the cover art, why is it doing this ?

Also, I don’t think it causes the problem but I am using Envers and the (seemingly) needless extra updates to the CoverArt table have the knock effect of causing Envers to create unneccessary Audit Tables as well.

If I remove the CascadeType annotation modifying the one field does not cause the cover art entities to be updated and everything works okay as long as I add the extra logic for when I do add cover art but I was hoping I didn’t need to do this.

  • 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-31T07:59:05+00:00Added an answer on May 31, 2026 at 7:59 am

    I seemed to have fixed the problem I was using the anti-pattern of creating a new session and then closing it whenever I retrieved anything from the DB rather than passing the method an existing session and only closing the session once I’ve finished with the object, fixing this has fixed the problem.

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

Sidebar

Related Questions

Hibernate allows you to just say .id. Let's say I have: @Entity public class
I have entity Territory class Territory { public int Id {get;set;} public string Title
I have an entity class Document and another one called Space. The relation: @ManyToOne(fetch
I have an entity class set up in Java, with a many-to-many relationship to
Is it possible to have an entity class which inherits from another (abstract) entity
All my Doctrine2 setups are done within YAML files. I have an entity class
We have entity Node: class Node(Entity): parent = ManyToOne('Node') children = OneToMany('Node') When we
I have an entity class and another class is Identity class of this entity.
Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A

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.