Hibernate 无主键多条件查询 推荐楼主这篇文章http://developer.51cto.com/art/200708/53178.htm 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 帮up一下,楼主可以把对应的POJOjava代码贴出来看看 PRoleMenuId 代码如下:public class PRoleMenuId implements java.io.Serializable { // Fields private PMenu Pmenu; private PRole Prole; // Constructors /** default constructor */ public PRoleMenuId() { } /** full constructor */ public PRoleMenuId(PMenu Pmenu, PRole Prole) { this.Pmenu = Pmenu; this.Prole = Prole; } // Property accessors public PMenu getPMenu() { return this.Pmenu; } public void setPMenu(PMenu Pmenu) { this.Pmenu = Pmenu; } public PRole getPRole() { return this.Prole; } public void setPRole(PRole PRole) { this.Prole = Prole; } public boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof PRoleMenuId)) return false; PRoleMenuId castOther = (PRoleMenuId) other; return ((this.getPMenu() == castOther.getPMenu()) || (this.getPMenu() != null && castOther.getPMenu() != null && this.getPMenu().equals( castOther.getPMenu()))) && ((this.getPRole() == castOther.getPRole()) || (this .getPRole() != null && castOther.getPRole() != null && this.getPRole() .equals(castOther.getPRole()))); } public int hashCode() { int result = 17; result = 37 * result + (getPMenu() == null ? 0 : this.getPMenu().hashCode()); result = 37 * result + (getPRole() == null ? 0 : this.getPRole().hashCode()); return result; }}PRoleMenu 代码如下:public class PRoleMenu implements java.io.Serializable { // Fields private PRoleMenuId id; // Constructors /** default constructor */ public PRoleMenu() { } /** full constructor */ public PRoleMenu(PRoleMenuId id) { this.id = id; } // Property accessors public PRoleMenuId getId() { return this.id; } public void setId(PRoleMenuId id) { this.id = id; }}同时感谢楼上的各位朋友..TO: 一楼的朋友,你的过淲器很好,我看了一下.但是最终写的还是 hql语句......还是无法解决这个问题. 我不是很理解的需求,但是我可以给个建议,看行不行:对于多表查询一般建议还是用关联查询比较的好,无论从效率还是速度上来说都有一定的优势,http://adoze.bokee.com/viewdiary.25283769.html,你可以到这里看看,也许对你有帮助的,里面介绍了很多关于hibernate的查询方式 问题解决了...呵呵,,一个很简单的方法...说出来有一些丢人了.. queryString.append("select m.menuId,m.menuName,"); queryString.append("m.descn,m.tip,m.leaf,m.sortNum, "); queryString.append("m.menuType,m.forward,m.target,m.image "); queryString.append("from PMenu as m,PRoleMenu as mr,"); queryString.append("PUser as su,PUserRole as sur "); queryString.append("where su.userId = sur.id.PUser "); queryString.append("and sur.id.PRole = mr.id.PRole "); queryString.append("and mr.id.PMenu = m.menuId "); queryString.append("and su.userId = " + userId ); queryString.append("and m.PMenu = " + perId);mr.id.PMenu 中的PMenu为当前的映射名...换成他就可以了... 求教一个servlet提交问题 线程大神们、高手们请进啊。。。求解啊 求oscache与jgroups使用例子(现在还没有找到会的人) ibatis queryForList方法取值问题 寻找 广州地区( JAVA爱好者 ) 用Java做Web service的来试试这个wsdl hibernate中一对多关联时,反向查询怎么写? 请问哪里可以下载到‘Sun认证Java2程序员学习指南(Exam 310-025)第二版(英文影印本)’这本书 JSP通过数据库显示图片的问题 用java 的jdbc 连接数据库 为什么javabean用不了???? EJB3.0 BEAN跟接口
private PRole Prole; // Constructors /** default constructor */
public PRoleMenuId() {
} /** full constructor */
public PRoleMenuId(PMenu Pmenu, PRole Prole) {
this.Pmenu = Pmenu;
this.Prole = Prole;
} // Property accessors public PMenu getPMenu() {
return this.Pmenu;
} public void setPMenu(PMenu Pmenu) {
this.Pmenu = Pmenu;
} public PRole getPRole() {
return this.Prole;
} public void setPRole(PRole PRole) {
this.Prole = Prole;
} public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof PRoleMenuId))
return false;
PRoleMenuId castOther = (PRoleMenuId) other; return ((this.getPMenu() == castOther.getPMenu()) || (this.getPMenu() != null
&& castOther.getPMenu() != null && this.getPMenu().equals(
castOther.getPMenu())))
&& ((this.getPRole() == castOther.getPRole()) || (this
.getPRole() != null
&& castOther.getPRole() != null && this.getPRole()
.equals(castOther.getPRole())));
} public int hashCode() {
int result = 17; result = 37 * result
+ (getPMenu() == null ? 0 : this.getPMenu().hashCode());
result = 37 * result
+ (getPRole() == null ? 0 : this.getPRole().hashCode());
return result;
}}
PRoleMenu 代码如下:
public class PRoleMenu implements java.io.Serializable { // Fields private PRoleMenuId id; // Constructors /** default constructor */
public PRoleMenu() {
} /** full constructor */
public PRoleMenu(PRoleMenuId id) {
this.id = id;
} // Property accessors public PRoleMenuId getId() {
return this.id;
} public void setId(PRoleMenuId id) {
this.id = id;
}}同时感谢楼上的各位朋友..TO: 一楼的朋友,你的过淲器很好,我看了一下.但是最终写的还是 hql语句......还是无法解决这个问题.
对于多表查询一般建议还是用关联查询比较的好,无论从效率还是速度上来说都有一定的优势,http://adoze.bokee.com/viewdiary.25283769.html,你可以到这里看看,也许对你有帮助的,里面介绍了很多关于hibernate的查询方式
queryString.append("m.descn,m.tip,m.leaf,m.sortNum, ");
queryString.append("m.menuType,m.forward,m.target,m.image ");
queryString.append("from PMenu as m,PRoleMenu as mr,");
queryString.append("PUser as su,PUserRole as sur ");
queryString.append("where su.userId = sur.id.PUser ");
queryString.append("and sur.id.PRole = mr.id.PRole ");
queryString.append("and mr.id.PMenu = m.menuId ");
queryString.append("and su.userId = " + userId );
queryString.append("and m.PMenu = " + perId);
mr.id.PMenu 中的PMenu为当前的映射名...换成他就可以了...