1

Dear All, I have a problem with an ArrayList annotated with @ElementCollection.

I need it to be an ArrayList, and when Hibernate load the object from the session, it is a hibernate Persistent List.

How can I solve the issue? I am using Hibernate with hibernate annotations, no JPA, so I can't do any @PostLoad

Best Regards

1
  • by the way, @ElementCollection is a JPA annotation ;) Commented Apr 12, 2011 at 18:55

1 Answer 1

9

Use a List instead of ArrayList:

@ElementCollection(..)
private List elements;

If you then want to do something with an ArrayList specifically, you can create a copy:

ArrayList list = new ArrayList(elements);

You need to use interfaces, because ORMs use custom implementations of these interfaces to achieve orm-specific functionality, e.g. lazy loading. Hibernate doesn't have a specific subclass of ArrayList, it has a PersistentList, which is justa List.

Sign up to request clarification or add additional context in comments.

2 Comments

depends on what "complex" means
Is there an alternative for XML configuration?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.