Search code examples
javajpabooleanpersistence

How to persist a Map<Key, Boolean> with the JPA


I have an Class in Java an their instances are JPA-@Enitit[ies], but they cannot be persisted, because I get a MappingException, because I have a map:

private Map<Account, Boolean> doneTask;

And I do not know how to persist a Boolean like a boolean.

What can I do?


Solution

  • Did you use ElementCollection? Something like:

    @ElementCollection
    @JoinTable(name="TASKS", joinColumns=@JoinColumn(name="ID"))
    @MapKeyColumn (name="ACCOUNT")
    @Column(name="DONE_FLAG")
    private Map<Account, Boolean> doneTask;