How to map an ArrayList of primitives to a single column?

前端 未结 4 2039
没有蜡笔的小新
没有蜡笔的小新 2020-12-31 11:02

Let\'s say I have the following situation:

Object Car has an ArrayList of prices, which are all numbers. Is it possible in Hibernate to save all the prices in a sin

4条回答
  •  隐瞒了意图╮
    2020-12-31 11:38

    AFAIR, Hibernate will use native serialization and store the resulting bytes in your column. I wouldn't do that though, and use a dedicated transformation that would make the prices readable in the database, and at least be able to use the data without needing Java native serialization:

    @Basic
    private String prices;
    
    public void setPrices(List prices) {
        this.prices = Joiner.on(',').join(prices);
    }
    
    public List getPrices() {
        List result = new ArrayList();
        for (String s : Splitter.on(',').split(this.prices)) {
            result.add(Integer.valueOf(s));
        }
        return result;
    }
    

提交回复
热议问题