枚举类
public enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,SATURDAY }
模型类
@Fetch(FetchMode.SUBSELECT)
@ElementCollection(targetClass = Days.class, fetch = FetchType.EAGER)
@JoinTable(name = "bus_days", joinColumns = @JoinColumn(name = "bus_master_id"))
@Column(name = "day", nullable = false)
@Enumerated(EnumType.ORDINAL)
private Set<Days> days = new HashSet<Days>();
// getter setter
hibernate 查询错误:
Criteria criteria = null;
criteria = session.createCriteria(Model.class)
.add(Restrictions.eq("fromCity.id", fromCity))
.add(Restrictions.eq("toCity.id", toCity))
.add(Restrictions.eq("days", days.ordinal()));//error in this line
return (List<Model>) criteria.list();
在 eclipse 控制台中获取错误;
Caused by: java.sql.SQLException: No value specified for parameter 3
ERROR: No value specified for parameter 3
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
帮助我,
最佳答案
你不应该通过days.ordinal()
进行比较,你只需要通过days
进行比较,hibernate自己将其转换为数字。
关于java - hibernate 枚举中多对多映射的条件限制如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45211506/