并非纯数据的休眠映射缓存结构化集合

时间:2018-10-20 10:14:34

标签: hibernate jpa

class Exchange { // singleton
    final class Order {
        int id;
        boolean sell;
        int price;
        int itemId;
        int n;
    }
    protected static final class Trading {
        // only contain order which sell is false
        SortedSet<Order> buy = new TreeSet<>(Comparator.comparingInt(o -> o.price));
        // only contain order which sell is true
        SortedSet<Order> sell = new TreeSet<>(Comparator.comparingInt(o -> o.price));
    }
    // Trading only contain order which itemId == map.key
    Map<Integer, Trading> trading = new HashMap<>(); 
}

如何将这个单例对象数据映射到包含列sell, price, itemId, n的单个表中?

我发现如果数据是以缓存的方式构造的(加快查找速度),则映射很难完成,因为JPA认为我的班级数据成员是数据,但不是。在上面的代码中,纯数据为Set<Order>,但是如果我在Exchange类中使用普通Set,则会降低性能,并且使用起来很不方便。

0 个答案:

没有答案
相关问题