Hibernate:将Map <string,object =“”>保存为RDBM作为序列化数据

时间:2017-06-02 14:04:50

标签: java hibernate jpa hibernate-mapping rdbms

如何通过Hibernate将无模式数据(Map<String, Object> schemalessParams)存储到RDBM中?

我需要做的就是坚持下去,阅读一次并忘记,不要按子字段或其他任何方式查询。我想应该有一种方法来序列化Map<String, Object>,而不是以某种方式反序列化它。至少同样的事情是由Quartz自动完成的。你知道如何用Hibernate注释做到这一点吗?

我的实体

@Entity
public class MyParams implements Serializable {

    @Id
    @SequenceGenerator(sequenceName = "MY_PARAMS_SEQ", name = "MyParamsSeq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MyParamsSeq")
    private Long id;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "job_id", nullable = false, updatable = false)
    private MyJob job;

    // QUESTION: How can I store schemalessParams field if value can be one of:     
    // Long,String,Integer,Boolean, Map<Long,Boolean>, List<LinkedHashMap<String, Integer>> etc.
    private Map<String, Object> schemalessParams;

0 个答案:

没有答案