编程语言
首页 > 编程语言> > java – 在ORMLite中保留Map而不诉诸DataType.SERIALIZABLE?

java – 在ORMLite中保留Map而不诉诸DataType.SERIALIZABLE?

作者:互联网

我有一个相对简单的类,主要由Map< String,String>支持.我想坚持这个类,并能够在地图内的键内搜索.基于这个Stack Overflow question,我感觉地图只能作为序列化的blob持久化.

我还在ORMLite website上看到以下内容:

public class Account {
    …
    @ForeignCollectionField(eager = false)
    ForeignCollection<Order> orders;
    …
}

In the above example, the @ForeignCollectionField annotation marks
that the orders field is a collection of the orders that match the
account. The field type of orders must be either ForeignCollection
or Collection<T> – no other collections are supported. The
@ForeignCollectionField annotation supports the following fields:

基于以上所述,我得到的印象是我想要的东西是不可能的,但我想我会在这里检查一下.我把它坚持在Hibernate中,但我宁愿使用像ORMLite那样更轻的东西!

解决方法:

是的,ORMLite没有办法坚持地图.遵循KISS原则,仅支持简单的Collection类. Set和Map对它们有更多的接口权重,可能永远不会得到支持.

我没有为你做任何超级棒的工作.您显然可以使用ForeignCollection,然后在需要以这种方式访问​​集合时创建一个本地Map字段.也许是一个addOrder()方法,可以将它添加到ForeignCollection和Map.

标签:java,orm,ormlite
来源: https://codeday.me/bug/20190729/1576037.html