hibernate3 多表的无外键约束时的查询

数据库中没有约束时,如何配置hibernate约束。

映射文件
...
...
		<!-- bi-directional many-to-one association to TbChannelInfo -->
		<many-to-one name="tbChannelInfo" class="com.coinv.mts.domain.TbChannelInfo"
			not-null="true">
			<meta attribute="field-description">
				@hibernate.many-to-one
				not-null="true"
				@hibernate.column name="DYTChannelID"         
	        </meta>
			<column name="DYTChannelID" />
		</many-to-one>
...
...




domain
public class TbDyDataTemp implements java.io.Serializable {
...
...
private TbChannelInfo tbChannelInfo;
	
	public TbChannelInfo getTbChannelInfo() {
		return tbChannelInfo;
	}

	public void setTbChannelInfo(TbChannelInfo tbChannelInfo) {
		this.tbChannelInfo = tbChannelInfo;
	}
...
...


dao
...
...
		DetachedCriteria criteria = 
			DetachedCriteria.forClass(TbDyDataTemp.class);
		
		criteria.add(Restrictions.in("dytdeviceId", deviceId));
		criteria.add(Restrictions.eq("dytvalid", Const_val.C_INT_VALID));
		criteria.createCriteria("tbChannelInfo").add(Restrictions.isNotNull("ciid"));

List<TbDyDataTemp> results = getHibernateTemplate().findByCriteria(criteria);
...
...

你可能感兴趣的:(hibernate3 多表的无外键约束时的查询)