How to map collections in Hibernate for PostgreSQL DB without using a mapping table?

I want to store String [] tags in my "Store" table. A repository object can have multiple tags and I see no reason to create a mapping table " store_tags

".

All relevant tags must be stored in the "Save" table. From what I can search the web, it seems that JPA / Hibernate is @ElementCollection

doing the annotation, but it needs a collection mapping table.

Is it possible to store and retrieve data as String[]

in a postgresql table through hibernation without creating any such mapping table?

Also, if this is not possible, would it be acceptable design to concatenate the String list into a string and store it in a table? Or will it have bad consequences? Please give some examples / points where these parameters may cause problems in the future.

I am using Java Play Framework, Hibernate and PostgreSQL.

+3


source to share


1 answer


If you really want to avoid using a separate table for the store_tag relationship, you might want to consider support hstore

with PostgreSL. However, you need to use the UserType implementation with hibernate (not the hibernate part of the kernel). Thus, the handling of the sleep mode can be inconvenient for the patient. Just storing and retrieving tags might be fine. Using tags with other aspects can be a strong argument for using a separate table.



As always, I would analyze common use cases for requests and modifications. And directly measure the performance effects of both options.

0


source







All Articles