简体   繁体   中英

What to use instead of @ElementCollection for JPA 1 från Java EE 5

Using: JPA 1 från Java EE 5:

My problem is as follows: I like to persist an Entity object containing a collection of numbers (Integer[]) with max lenght 3.

This solution works for Java EE 6: (annotation) ElementCollection private List productIds = new ArrayList();

What is the correct solution in Java EE5 and JPA 1. I have been told to use hibernate specific annotations, but this technique is new to me.

I have tried with (annotation) CollectionOfElements, org.hibernate.annotations.CollectionOfElements, but the Array is saved as serialized object and not readable in the database.

Grateful for any answer that lead me in the right direction!

Since ElementCollection was introduced in JPA 2 to overcome the problem of mapping a colletion of primitive datatypes, using CollectionOfElements for a Hibernate-specific solution is basically fine.

If you want to have it stored in a relational way, you might either go and have 3 columns (in case this is fix), or have another table mapped with usual One-To-Many relation and wrap your primitive type into a specific class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM