简体   繁体   中英

Hibernate - how to persist Map<UUID,POJO>

i cant find what is wrong with my annotations (i have used official hibernate documentation)

public class DashletContainer{

private Map<UUID, DashletData> dashletData = new HashMap<>();
//STUFF

    @OneToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "rd_container_data")
    @MapKeyColumn(name = "dashletdata_dashlet_id")
    public Map<UUID, DashletData> getDashletData() {
        return dashletData;
    }
}


public class DashletData{

//STUFF

    @Column(name = "dashlet_id")
    public UUID getDashletId() {
        return dashletId;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    public DashletContainer getDashletContainer() {
        return dashletContainer;
    }
}

and this is the structure of my join table(rd_container_data) on database :

dashletdata_id      | UUID
dashletcontainer_id | UUID
dashletdata_dashlet_id  | UUID

the problem is when i persist the container object the Map inside it stays Null and nothing get inserted inside corresponding table.

thank you

@dave尝试在属性dashletData上添加@MapKeyColumn(name = "dashletdata_dashlet_id")而不是getter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM