Hibernate (JPA) displaying a HashMap

Prereading:

How to save a HashMap using sleep mode

My problem rotates the following structure that I want to map to JPA:

Map<User, List<POJO>> 

My POJO is very simple (no compound types, etc., only some primitives).

How can I implement advice in a related question? How can I comment only on the List part using @Lob (When I just comment on the field, I get a class cast error because the HashMap cannot be attributed to Blob, which is the root of my problem - it annotates only the values โ€‹โ€‹of the map part)?

I'm not sure if I need to create a wrapper type that implements Serializable that wraps a List, or enough to just use an ArrayList, which itself is Serializable. And in any case, I canโ€™t save this copy of the map ...

By the way, I am open to advice on this in different ways: I could just hold List as a member of the class for each user, although I donโ€™t feel that it belongs there because it is not user data (like account data, name, address, etc.). It is similar to purchases, so I put them in a class similar to a utility (external to the User class) that deals with these purchases in order to have more modular models. I would like to hear advice on whether this sounds reasonable.

Any useful tips will be rewarded with imaginary cookies (and vice versa, obviously).
They are fat-free in a very imaginary sense.

Greetings.

+4
source share
1 answer

If you have a card, you probably have a one-to-many relationship. Attach your list to User and make POJO an entity and donโ€™t be fooled by @Lob. A map is a catastrophe awaiting events (hash value / equal problems) and does not provide a pure database mapping.

+2
source

Source: https://habr.com/ru/post/1343242/


All Articles