Mapping collection inside container entity to one table


I have the following class structure:

public class Container {

    private Set<Child> childs  = new HashSet<>();

public class Child {
    String name;
    String value;
    String param;

Because of Container class is going to be single in application (just wrapper on collections that may be updated), I would like to store it in one table, e.g.“childs” with columns

id | name | value | param
Is it possible to make such mapping in order to use Container when fetch or store it through hb session with corresponding updates to childs collection:

And if so, what mapping should be in that case?


The Container entity is the parent.

That means the Child needs to have a FK back to its Parent.

So, the Container entity needs to be backed by a container table so that its PK is referenced by the Child table FK.

That’s how a one-to-many table relationship works.

For more details bout how to map this association, check out this article.


Thanks for the reply!
I am still confused is it possible to map using one table. If we have ids fields in table. So container_id will always the same and child_id will be different and that’s what pk would be

container_id | child_id | name | value | param


So, if there is no container table, is that value coming from some external system?

You cannot map an entity without having a table. Theoretically, you could map the Container entity to a View using an SQL query like this one:

select distinct container_id as id
from child

and the Container entity becomes:

@Table(name = "container_view ")  
public class Container{
    @Column(name = "id")
    private Long id;