Home Saving Entity with a Map
Reply: 0

Saving Entity with a Map

user618
1#
user618 Published in April 25, 2018, 6:16 pm

Is there any way I could persist an entity and It's map at the same time?

This example, for instance

public class Test {

    private @Id @GeneratedValue(strategy = AUTO) Long id;
    private String name;

    @ElementCollection(targetClass = Long.class)
    @CollectionTable(name = "test1_id")
    @MapKeyColumn(name = "test_id")
    @Column(name = "test")
    private Map<Long, Long> map = new HashMap<>();
}

So when I do test.getMap().put(1L, 2L) then testRepository.save(test) it saves the entity as well as the map?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.459092 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO