Struts+Hibernate映射无主键表的问题 只要你不根据主键id取单条记录其他都是一样的取出符合条件的list即可 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 但取出 list 之后也要类型转换啊!因为他生成了两个java文件,我不知道怎么处理了!请指教~~~~ AbstractAuthors.java AuthorsId.java不管它,你取出list集合用Authors.java转换如果model里有AuthorsId的话就把它去掉.xml文件里也一样,保留里边的属性就可以了.不过很奇怪,为什么你要这么做,没有主键的表,至少也要是个复合主键啊 这是映射文件<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!-- Mapping file autogenerated by MyEclipse - Hibernate Tools--><hibernate-mapping> <class name="com.lichen.infocenter.hibernate.mapping.Wzcxtemp" table="WZCXTEMP" schema="EDDIE"> <composite-id name="id" class="com.lichen.infocenter.hibernate.mapping.WzcxtempId"> <key-property name="ch" type="java.lang.String"> <column name="CH" length="20" /> </key-property> <key-property name="cx" type="java.lang.String"> <column name="CX" length="16" /> </key-property> <key-property name="cz" type="java.lang.String"> <column name="CZ" length="80" /> </key-property> <key-property name="wzdate" type="java.lang.String"> <column name="WZDATE" length="20" /> </key-property> <key-property name="wzdd" type="java.lang.String"> <column name="WZDD" length="80" /> </key-property> <key-property name="wzxw" type="java.lang.String"> <column name="WZXW" length="80" /> </key-property> <key-property name="wzsxh" type="java.lang.String"> <column name="WZSXH" length="20" /> </key-property> <key-property name="cldw" type="java.lang.String"> <column name="CLDW" length="80" /> </key-property> <key-property name="pzdm" type="java.lang.String"> <column name="PZDM" length="40" /> </key-property> <key-property name="wzcldz" type="java.lang.String"> <column name="WZCLDZ" length="80" /> </key-property> <key-property name="lxdh" type="java.lang.String"> <column name="LXDH" length="20" /> </key-property> <key-property name="flag" type="java.lang.String"> <column name="FLAG" length="2" /> </key-property> </composite-id> </class></hibernate-mapping> 这是 Wzcxtemp 类::package com.lichen.infocenter.hibernate.mapping;// Generated by MyEclipse - Hibernate Tools/** * Wzcxtemp generated by MyEclipse - Hibernate Tools */public class Wzcxtemp extends AbstractWzcxtemp implements java.io.Serializable { // Constructors /** default constructor */ public Wzcxtemp() { } /** full constructor */ public Wzcxtemp(WzcxtempId id) { super(id); } }这是 WzcxtempId 类::package com.lichen.infocenter.hibernate.mapping;/** * WzcxtempId generated by MyEclipse - Hibernate Tools */public class WzcxtempId implements java.io.Serializable { // Fields private String ch; private String cx; private String cz; private String wzdate; private String wzdd; private String wzxw; private String wzsxh; private String cldw; private String pzdm; private String wzcldz; private String lxdh; private String flag; // Constructors /** default constructor */ public WzcxtempId() { } // Property accessors public String getCh() { return this.ch; } public void setCh(String ch) { this.ch = ch; } public String getCx() { return this.cx; } public void setCx(String cx) { this.cx = cx; } public String getCz() { return this.cz; } public void setCz(String cz) { this.cz = cz; } public String getWzdate() { return this.wzdate; } public void setWzdate(String wzdate) { this.wzdate = wzdate; } public String getWzdd() { return this.wzdd; } public void setWzdd(String wzdd) { this.wzdd = wzdd; } public String getWzxw() { return this.wzxw; } public void setWzxw(String wzxw) { this.wzxw = wzxw; } public String getWzsxh() { return this.wzsxh; } public void setWzsxh(String wzsxh) { this.wzsxh = wzsxh; } public String getCldw() { return this.cldw; } public void setCldw(String cldw) { this.cldw = cldw; } public String getPzdm() { return this.pzdm; } public void setPzdm(String pzdm) { this.pzdm = pzdm; } public String getWzcldz() { return this.wzcldz; } public void setWzcldz(String wzcldz) { this.wzcldz = wzcldz; } public String getLxdh() { return this.lxdh; } public void setLxdh(String lxdh) { this.lxdh = lxdh; } public String getFlag() { return this.flag; } public void setFlag(String flag) { this.flag = flag; } public boolean equals(Object other) { if ( (this == other ) ) return true; if ( (other == null ) ) return false; if ( !(other instanceof WzcxtempId) ) return false; WzcxtempId castOther = ( WzcxtempId ) other; return ( (this.getCh()==castOther.getCh()) || ( this.getCh()!=null && castOther.getCh()!=null && this.getCh().equals(castOther.getCh()) ) ) && ( (this.getCx()==castOther.getCx()) || ( this.getCx()!=null && castOther.getCx()!=null && this.getCx().equals(castOther.getCx()) ) ) && ( (this.getCz()==castOther.getCz()) || ( this.getCz()!=null && castOther.getCz()!=null && this.getCz().equals(castOther.getCz()) ) ) && ( (this.getWzdate()==castOther.getWzdate()) || ( this.getWzdate()!=null && castOther.getWzdate()!=null && this.getWzdate().equals(castOther.getWzdate()) ) ) && ( (this.getWzdd()==castOther.getWzdd()) || ( this.getWzdd()!=null && castOther.getWzdd()!=null && this.getWzdd().equals(castOther.getWzdd()) ) ) && ( (this.getWzxw()==castOther.getWzxw()) || ( this.getWzxw()!=null && castOther.getWzxw()!=null && this.getWzxw().equals(castOther.getWzxw()) ) ) && ( (this.getWzsxh()==castOther.getWzsxh()) || ( this.getWzsxh()!=null && castOther.getWzsxh()!=null && this.getWzsxh().equals(castOther.getWzsxh()) ) ) && ( (this.getCldw()==castOther.getCldw()) || ( this.getCldw()!=null && castOther.getCldw()!=null && this.getCldw().equals(castOther.getCldw()) ) ) && ( (this.getPzdm()==castOther.getPzdm()) || ( this.getPzdm()!=null && castOther.getPzdm()!=null && this.getPzdm().equals(castOther.getPzdm()) ) ) && ( (this.getWzcldz()==castOther.getWzcldz()) || ( this.getWzcldz()!=null && castOther.getWzcldz()!=null && this.getWzcldz().equals(castOther.getWzcldz()) ) ) && ( (this.getLxdh()==castOther.getLxdh()) || ( this.getLxdh()!=null && castOther.getLxdh()!=null && this.getLxdh().equals(castOther.getLxdh()) ) ) && ( (this.getFlag()==castOther.getFlag()) || ( this.getFlag()!=null && castOther.getFlag()!=null && this.getFlag().equals(castOther.getFlag()) ) ); } public int hashCode() { int result = 17; result = 37 * result + ( getCh() == null ? 0 : this.getCh().hashCode() ); result = 37 * result + ( getCx() == null ? 0 : this.getCx().hashCode() ); result = 37 * result + ( getCz() == null ? 0 : this.getCz().hashCode() ); result = 37 * result + ( getWzdate() == null ? 0 : this.getWzdate().hashCode() ); result = 37 * result + ( getWzdd() == null ? 0 : this.getWzdd().hashCode() ); result = 37 * result + ( getWzxw() == null ? 0 : this.getWzxw().hashCode() ); result = 37 * result + ( getWzsxh() == null ? 0 : this.getWzsxh().hashCode() ); result = 37 * result + ( getCldw() == null ? 0 : this.getCldw().hashCode() ); result = 37 * result + ( getPzdm() == null ? 0 : this.getPzdm().hashCode() ); result = 37 * result + ( getWzcldz() == null ? 0 : this.getWzcldz().hashCode() ); result = 37 * result + ( getLxdh() == null ? 0 : this.getLxdh().hashCode() ); result = 37 * result + ( getFlag() == null ? 0 : this.getFlag().hashCode() ); return result; } } 呵呵...可以使用 Query query=session.createQuery("from Wzcxtemp a");查询总记录数,但不知道应该如何把数据显示出来! 解决了...Session session=SessionFactory.currentSession();Query query=session.createQuery("from Wzcxtemp a");query.setMaxResults(10);WzcxtempId wzid=new WzcxtempId();Wzcxtemp wz=(Wzcxtemp)session.load(Wzcxtemp.class,wzid);List list=query.list();int size=list.size();for(int i=0;i<size;i++){ wz=(Wzcxtemp)list.get(i); System.out.println(wz.getId().getCh());}就可以了 分布式服务器,怎么防止表单重复提交,在线等,急!!! 事务回滚的问题 多个结构相同的数据库数据合并问题 hibernate 还需要那第三方插件::: tomcat在eclipse中启不来,说是ddress already in use: JVM_Bind:8080 SpringMVC的Converter问题 监听器的问题 求好的j2ee书籍(纸版),来者有分 java里如何把一个String变成文件然后通过post请求上传 java评论系统 关于struts的问题 (JSF)Java的生旦净末丑!
AuthorsId.java
不管它,你取出list集合用Authors.java转换
如果model里有AuthorsId的话就把它去掉.xml文件里也一样,保留里边的属性就可以了.不过很奇怪,为什么你要这么做,没有主键的表,至少也要是个复合主键啊
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.lichen.infocenter.hibernate.mapping.Wzcxtemp" table="WZCXTEMP" schema="EDDIE">
<composite-id name="id" class="com.lichen.infocenter.hibernate.mapping.WzcxtempId">
<key-property name="ch" type="java.lang.String">
<column name="CH" length="20" />
</key-property>
<key-property name="cx" type="java.lang.String">
<column name="CX" length="16" />
</key-property>
<key-property name="cz" type="java.lang.String">
<column name="CZ" length="80" />
</key-property>
<key-property name="wzdate" type="java.lang.String">
<column name="WZDATE" length="20" />
</key-property>
<key-property name="wzdd" type="java.lang.String">
<column name="WZDD" length="80" />
</key-property>
<key-property name="wzxw" type="java.lang.String">
<column name="WZXW" length="80" />
</key-property>
<key-property name="wzsxh" type="java.lang.String">
<column name="WZSXH" length="20" />
</key-property>
<key-property name="cldw" type="java.lang.String">
<column name="CLDW" length="80" />
</key-property>
<key-property name="pzdm" type="java.lang.String">
<column name="PZDM" length="40" />
</key-property>
<key-property name="wzcldz" type="java.lang.String">
<column name="WZCLDZ" length="80" />
</key-property>
<key-property name="lxdh" type="java.lang.String">
<column name="LXDH" length="20" />
</key-property>
<key-property name="flag" type="java.lang.String">
<column name="FLAG" length="2" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
// Generated by MyEclipse - Hibernate Tools/**
* Wzcxtemp generated by MyEclipse - Hibernate Tools
*/
public class Wzcxtemp extends AbstractWzcxtemp implements java.io.Serializable { // Constructors /** default constructor */
public Wzcxtemp() {
}
/** full constructor */
public Wzcxtemp(WzcxtempId id) {
super(id);
}
}这是 WzcxtempId 类::
package com.lichen.infocenter.hibernate.mapping;/**
* WzcxtempId generated by MyEclipse - Hibernate Tools
*/public class WzcxtempId implements java.io.Serializable {
// Fields private String ch;
private String cx;
private String cz;
private String wzdate;
private String wzdd;
private String wzxw;
private String wzsxh;
private String cldw;
private String pzdm;
private String wzcldz;
private String lxdh;
private String flag;
// Constructors /** default constructor */
public WzcxtempId() {
}
// Property accessors public String getCh() {
return this.ch;
}
public void setCh(String ch) {
this.ch = ch;
} public String getCx() {
return this.cx;
}
public void setCx(String cx) {
this.cx = cx;
} public String getCz() {
return this.cz;
}
public void setCz(String cz) {
this.cz = cz;
} public String getWzdate() {
return this.wzdate;
}
public void setWzdate(String wzdate) {
this.wzdate = wzdate;
} public String getWzdd() {
return this.wzdd;
}
public void setWzdd(String wzdd) {
this.wzdd = wzdd;
} public String getWzxw() {
return this.wzxw;
}
public void setWzxw(String wzxw) {
this.wzxw = wzxw;
} public String getWzsxh() {
return this.wzsxh;
}
public void setWzsxh(String wzsxh) {
this.wzsxh = wzsxh;
} public String getCldw() {
return this.cldw;
}
public void setCldw(String cldw) {
this.cldw = cldw;
} public String getPzdm() {
return this.pzdm;
}
public void setPzdm(String pzdm) {
this.pzdm = pzdm;
} public String getWzcldz() {
return this.wzcldz;
}
public void setWzcldz(String wzcldz) {
this.wzcldz = wzcldz;
} public String getLxdh() {
return this.lxdh;
}
public void setLxdh(String lxdh) {
this.lxdh = lxdh;
} public String getFlag() {
return this.flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof WzcxtempId) ) return false;
WzcxtempId castOther = ( WzcxtempId ) other;
return ( (this.getCh()==castOther.getCh()) || ( this.getCh()!=null && castOther.getCh()!=null && this.getCh().equals(castOther.getCh()) ) )
&& ( (this.getCx()==castOther.getCx()) || ( this.getCx()!=null && castOther.getCx()!=null && this.getCx().equals(castOther.getCx()) ) )
&& ( (this.getCz()==castOther.getCz()) || ( this.getCz()!=null && castOther.getCz()!=null && this.getCz().equals(castOther.getCz()) ) )
&& ( (this.getWzdate()==castOther.getWzdate()) || ( this.getWzdate()!=null && castOther.getWzdate()!=null && this.getWzdate().equals(castOther.getWzdate()) ) )
&& ( (this.getWzdd()==castOther.getWzdd()) || ( this.getWzdd()!=null && castOther.getWzdd()!=null && this.getWzdd().equals(castOther.getWzdd()) ) )
&& ( (this.getWzxw()==castOther.getWzxw()) || ( this.getWzxw()!=null && castOther.getWzxw()!=null && this.getWzxw().equals(castOther.getWzxw()) ) )
&& ( (this.getWzsxh()==castOther.getWzsxh()) || ( this.getWzsxh()!=null && castOther.getWzsxh()!=null && this.getWzsxh().equals(castOther.getWzsxh()) ) )
&& ( (this.getCldw()==castOther.getCldw()) || ( this.getCldw()!=null && castOther.getCldw()!=null && this.getCldw().equals(castOther.getCldw()) ) )
&& ( (this.getPzdm()==castOther.getPzdm()) || ( this.getPzdm()!=null && castOther.getPzdm()!=null && this.getPzdm().equals(castOther.getPzdm()) ) )
&& ( (this.getWzcldz()==castOther.getWzcldz()) || ( this.getWzcldz()!=null && castOther.getWzcldz()!=null && this.getWzcldz().equals(castOther.getWzcldz()) ) )
&& ( (this.getLxdh()==castOther.getLxdh()) || ( this.getLxdh()!=null && castOther.getLxdh()!=null && this.getLxdh().equals(castOther.getLxdh()) ) )
&& ( (this.getFlag()==castOther.getFlag()) || ( this.getFlag()!=null && castOther.getFlag()!=null && this.getFlag().equals(castOther.getFlag()) ) );
}
public int hashCode() {
int result = 17;
result = 37 * result + ( getCh() == null ? 0 : this.getCh().hashCode() );
result = 37 * result + ( getCx() == null ? 0 : this.getCx().hashCode() );
result = 37 * result + ( getCz() == null ? 0 : this.getCz().hashCode() );
result = 37 * result + ( getWzdate() == null ? 0 : this.getWzdate().hashCode() );
result = 37 * result + ( getWzdd() == null ? 0 : this.getWzdd().hashCode() );
result = 37 * result + ( getWzxw() == null ? 0 : this.getWzxw().hashCode() );
result = 37 * result + ( getWzsxh() == null ? 0 : this.getWzsxh().hashCode() );
result = 37 * result + ( getCldw() == null ? 0 : this.getCldw().hashCode() );
result = 37 * result + ( getPzdm() == null ? 0 : this.getPzdm().hashCode() );
result = 37 * result + ( getWzcldz() == null ? 0 : this.getWzcldz().hashCode() );
result = 37 * result + ( getLxdh() == null ? 0 : this.getLxdh().hashCode() );
result = 37 * result + ( getFlag() == null ? 0 : this.getFlag().hashCode() );
return result;
}
}
Session session=SessionFactory.currentSession();
Query query=session.createQuery("from Wzcxtemp a");
query.setMaxResults(10);WzcxtempId wzid=new WzcxtempId();
Wzcxtemp wz=(Wzcxtemp)session.load(Wzcxtemp.class,wzid);List list=query.list();
int size=list.size();for(int i=0;i<size;i++){
wz=(Wzcxtemp)list.get(i);
System.out.println(wz.getId().getCh());
}就可以了