相关疑难解决方法(0)

关于集合值的Hibernate标准

我正在尝试使用Hibernate组合一个复杂的查询.我一直倾向于Criteria,但我开始怀疑它不可能,所以任何建议都会有所帮助.

我有一个如下的实体结构:

public class Attribute {
    private Integer id;
    private String name;
    private Set<Value> values;
}

public class Instance {
    private Integer id;
    private int instanceRef;
    private Set<Value> values;
}

public class Value {
    private Integer id;
    private Attribute attribute;
    private String localAttributeName;
    private Instance instance;
    private String value;
}
Run Code Online (Sandbox Code Playgroud)

这些实体与您期望的相关:

value.attribute_id --> attribute.id
value.instance_id --> instance.id
Run Code Online (Sandbox Code Playgroud)

现在,我希望能够获取一组属性/值对(字符串)并查找包含所有这些属性/值对的所有实例.在Value中,attribute和localAttributeName中只有一个是非null,因此属性名称可以匹配localAttributeName或attribute.name.最后一次使事情复杂化,Value上的唯一索引是(实例,属性,值)或(实例,localAttributeName,value) - 也就是说,在实例中,任何给定的Attribute都可能有多个值.

这是我到目前为止:

public List<Instance> getMatchingInstances(Map<String, String> attrValues) {
    Criteria crit = session.createCriteria(Instance.class, "i");
    for(Map.Entry<String, String> entry : attrValues) { …
Run Code Online (Sandbox Code Playgroud)

java orm hibernate hibernate-criteria

12
推荐指数
1
解决办法
3万
查看次数

收集表的Hibernate条件查询?

我有以下实体

@Entity
@Table(name = "rule")
public class Rule implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "rule_id")
    private Long id;

    @ElementCollection(targetClass = Action.class)


     @CollectionTable(name = "rule_action", joinColumns = @JoinColumn(name = "rule_id"))
        @Enumerated(value = EnumType.STRING)
        @Column(name = "action")
        private Set<Action> actions;

//After editing as per jbrookover's suggestion adding a new mapping
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
       @JoinColumn(name = "rule_id")
       private Set<RuleAction> ruleActions;


    }
Run Code Online (Sandbox Code Playgroud)

以下是我的行动

public enum Action {
    PHONE, EMAIL, POSTAL,PHONE_OR_EMAIL, SMS;
}
Run Code Online (Sandbox Code Playgroud)

我想获取一个规则列表,其中包含我正在尝试此操作的特定操作集

 DetachedCriteria criteria = DetachedCriteria.forClass(Rule.class,"rule");
 criteria …
Run Code Online (Sandbox Code Playgroud)

hibernate hibernate-criteria

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

hibernate ×2

hibernate-criteria ×2

java ×1

orm ×1