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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:34:17+00:00 2026-06-15T17:34:17+00:00

I have a business object that exposes a list of elements for which want

  • 0

I have a business object that exposes a list of elements for which want to have control on.

For that, I have created a custom List implementation (CustomList) with a listener to be notified whenever an an element added / removed.

public class MyClass {
    private List<ItemClass> list;

    public MyClass() {
        this.list = new CustomList<ItemClass>();
    }

    public List<ItemClass> getList() {...}
    public setList(List<ItemClass>) {...}
}

The problem is that, if I want to persist this object, Hibernate uses the setter to set the list with its own List implementation, thus short-circuiting my nice CostumList bahavior.

I have tried to cheat with the setter, this way :

public setList(List<ItemClass> newList) {
    this.list.clean():
    this.list.addAll(newList);
}

But this does not work either :
Hibernate calls the setter first, and then add some elements to its own list. Therefore, I end up with an empty list on my side.

Is there a way I can ask hibernate to use my custom list implementation ? Or to fill it after has loaded the contents ?

Thanks in advance for your help.

  • 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-06-15T17:34:18+00:00Added an answer on June 15, 2026 at 5:34 pm

    My first thought was to do something like this:

    You could always use the setter to change the list implementation
    (similar to what you have done). For instance:

    public setList(List<ItemClass> newList) {
        // Sets the list as a custom list.
        list = new CustomList<>(newList);
    }
    

    Yet, for that to work, you need to change the implementation of your
    CustomList to work as a decorator, so it will work independently of the wrapped list type.

    As @millimoose has noticed, it still does not solve your problem.

    A working solution could be found by using the Hibernate (or JPA) lifecycle annotations (such as @PostPersist, @PostUpdate or @PostLoad…). So, you could use that customList.addAll() solution (after the entity has been updated, persisted or loaded).

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

Sidebar

Related Questions

I have an object that has a list of business rules that are checked
So I have a business object that supports a Save-method which does some IO
I have a business object that compiles into a DLL that handles all calculations
Lets say that you have a business object whose current state implies that there
I have a service object that is responsible for some business logic validation. What
I have a business object project, which contains composite structure: public class Tree {
So, I have a ListBox which is bound to a list of business objects,
I have a business object that I need to change one of its properties.
Assume I have a business object that has some properties that should be read-only.
In the following scenario, you have a business object called Employee that contains all

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.