我有两个 tables Customer and Contact. One customer can have multiple contacts.
是一对多的关系。两个entity的部分代码如下
Part of Customer Entity:
@OneToMany(cascade = CascadeType.REFRESH, mappedBy="customer", fetch = FetchType.EAGER)
private Set<Contact> contacts;Part of Contact Entity:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_ID")
private Customer customer;@Column(name = "FIELD_NAME")
@NotNull
private String fieldName;@Column(name = "FIELD_VALUE")
@Length(max = 100, message = "Maximum length allowed for user defined field is 100")
private String fieldValue;现在要写一条查询jpql语句,根据contact表的fieldName和fieldValue查询
For example, the criteria is fieldName='home number' and fieldValue='1234'怎么写这样的jpql语句?
我试过这样写不对
select c from Customer c where c.contacts.fieldName='home number' and c.contacts.fieldValue='1234'
是一对多的关系。两个entity的部分代码如下
Part of Customer Entity:
@OneToMany(cascade = CascadeType.REFRESH, mappedBy="customer", fetch = FetchType.EAGER)
private Set<Contact> contacts;Part of Contact Entity:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_ID")
private Customer customer;@Column(name = "FIELD_NAME")
@NotNull
private String fieldName;@Column(name = "FIELD_VALUE")
@Length(max = 100, message = "Maximum length allowed for user defined field is 100")
private String fieldValue;现在要写一条查询jpql语句,根据contact表的fieldName和fieldValue查询
For example, the criteria is fieldName='home number' and fieldValue='1234'怎么写这样的jpql语句?
我试过这样写不对
select c from Customer c where c.contacts.fieldName='home number' and c.contacts.fieldValue='1234'
解决方案 »
- 请教一个在jsp中等待的问题。哪位知道给指点一下
- 请教异常处理问题
- 求助!!axis 四种实现方式。。document,wrapped方式怎么实现?
- 对hibernate中用ThreadLocal管理Session和Transaction的一点疑问。
- SSH框架,Action中复杂自定义方法调用问题?--看看有收获
- 如何在java中把我生成的htm保存为我特定的文件格式--保存起来
- 请问大家,在单cpu上使用线程池有什么意义吗?
- Lomboz是什么?
- weblogic和IIS可以在一台机器上运行吗?
- shiro+ehcache+session管理问题
- jbpm4怎么和业务数据绑定
- 正则表达式求助
hibernate可能熟悉的多一些,那要是hibernate的query应该是怎么样的?