- 浏览: 1523900 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (532)
- 软件设计师 (7)
- PSP (5)
- NET MD (9)
- Hibernate (8)
- DIY (51)
- Work (43)
- GAME (24)
- 未分类 (44)
- iPod (6)
- MySQL (39)
- JSP (7)
- 日语能力考试 (36)
- 小说 (4)
- 豆包网 (23)
- 家用电脑 (7)
- DB2 (36)
- C/C++ (18)
- baby (9)
- Linux (13)
- thinkpad (23)
- OA (1)
- UML (6)
- oracle (24)
- 系统集成 (27)
- 脑梗塞 (6)
- 车 (8)
- MainFrame (8)
- Windows 7 (13)
- 手机 (8)
- git (12)
- AHK (2)
- COBOL (2)
- Java (9)
最新评论
-
安静听歌:
... ...
UUID做主键,好还是不好?这是个问题。 -
lehehe:
http://www.haoservice.com/docs/ ...
天气预报 -
lehehe:
[url http://www.haoservice.com/ ...
天气预报 -
liubang201010:
监控TUXEDO 的软件推荐用这个,专业,权威.并能提供报警和 ...
(转载)Tuxedo中间件简介 -
tinkame:
Next[j] =-1 当j=0时;=Max{k|0<k ...
KMP字符串模式匹配详解
在ms sql server 数据库中,有一个表Authors(注:此表没有主键列),用MyEclipse的hibernate生成的映射中出现四个文件,AbstractAuthors.java,Authors.java,AuthorsId.java,Authors.hbm.xml
表中有一个列是AuthName,但这列不是主键,因为AuthName可以重复,没有自增列.
现在的问题是我应该怎么做才能把数据库的数据取出来?
回复:Struts+Hibernate映射无主键表的问题
只要你不根据主键id取单条记录
其他都是一样的
取出符合条件的list即可
回复:Struts+Hibernate映射无主键表的问题
但取出 list 之后也要类型转换啊!因为他生成了两个java文件,我不知道怎么处理了!
请指教~~~~
回复:Struts+Hibernate映射无主键表的问题
AbstractAuthors.java
AuthorsId.java
不管它,你取出list集合用Authors.java转换
如果model里有AuthorsId的话就把它去掉.xml文件里也一样,保留里边的属性就可以了.
不过很奇怪,为什么你要这么做,没有主键的表,至少也要是个复合主键啊
回复:Struts+Hibernate映射无主键表的问题
这是映射文件
回复:Struts+Hibernate映射无主键表的问题
这是 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;
}
}
回复:Struts+Hibernate映射无主键表的问题
头有点晕
回复:Struts+Hibernate映射无主键表的问题
呵呵...可以使用 Query query=session.createQuery("from Wzcxtemp a");查询总记录数,
但不知道应该如何把数据显示出来!
回复:Struts+Hibernate映射无主键表的问题
解决了...
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 wz=(Wzcxtemp)list.get(i);
System.out.println(wz.getId().getCh());
}
就可以了
回复:Struts+Hibernate映射无主键表的问题
郁闷,如果是这样的话,那如果要进行条件查询呢?
表中有一个列是AuthName,但这列不是主键,因为AuthName可以重复,没有自增列.
现在的问题是我应该怎么做才能把数据库的数据取出来?
回复:Struts+Hibernate映射无主键表的问题
只要你不根据主键id取单条记录
其他都是一样的
取出符合条件的list即可
回复:Struts+Hibernate映射无主键表的问题
但取出 list 之后也要类型转换啊!因为他生成了两个java文件,我不知道怎么处理了!
请指教~~~~
回复:Struts+Hibernate映射无主键表的问题
AbstractAuthors.java
AuthorsId.java
不管它,你取出list集合用Authors.java转换
如果model里有AuthorsId的话就把它去掉.xml文件里也一样,保留里边的属性就可以了.
不过很奇怪,为什么你要这么做,没有主键的表,至少也要是个复合主键啊
回复:Struts+Hibernate映射无主键表的问题
这是映射文件
xml 代码
- <!---->xml version="1.0"?>
- <!---->
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
- <!---->
- <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>
回复:Struts+Hibernate映射无主键表的问题
这是 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;
}
}
回复:Struts+Hibernate映射无主键表的问题
头有点晕
回复:Struts+Hibernate映射无主键表的问题
呵呵...可以使用 Query query=session.createQuery("from Wzcxtemp a");查询总记录数,
但不知道应该如何把数据显示出来!
回复:Struts+Hibernate映射无主键表的问题
解决了...
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 wz=(Wzcxtemp)list.get(i);
System.out.println(wz.getId().getCh());
}
就可以了
回复:Struts+Hibernate映射无主键表的问题
郁闷,如果是这样的话,那如果要进行条件查询呢?
发表评论
-
Hibernate中对无主键表的操作
2007-09-12 19:55 4334Db2 表:Test 只有一个测试字段:name char ... -
Hibernate3.x调用存储过程大揭密
2007-07-26 19:34 4124Hibernate3.x调用存储过程 ... -
Hibernate 3中的formula
2007-07-17 13:57 2426Hibernate 3中的formula ... -
Hibernate代码生成工具 设计全攻略
2007-06-29 22:11 2486... -
Hibernate Tag 参考手册(中文翻译版1.0)
2007-06-22 11:38 1463Hibernate Tag 参考手册(中文翻译版1.0) ... -
Spring+Hibernate的saveOrUpdate问题
2007-06-22 11:35 57631.S ... -
采用p6spy完整显示hibernate的SQL语句
2007-06-21 17:26 2006采用p6spy完整显示hibernate的SQL语句 作者: ...
相关推荐
hibernate 无主键表映射资源说明: 1. 简单Demo 2. Demo对应的sql语句 3. 对应博客文档
NULL 博文链接:https://zhangzhi199129.iteye.com/blog/1663919
联合主键用Hibernate注解映射方式主要有三种: 第一、将联合主键的字段单独放在一个类中,该类需要实现java.io.Serializable接口并重写equals和hascode,再将该类注解为@Embeddable,最后在主类中(该类不包含联合主键...
复合主键映射 <br>通常将复合主键相关属性,单独抽取出来,建立一个独立的类 * 必须实现序列化接口 * 必须实现equals和hashcode方法 采用标签进行映射,其它属性采用正常映射
hibernata 映射主键自动生成,跨数据库时,如何设置,主要讲述在oracle的mapping文件中的设置,以及orcle数据库中的设置
关于hiberante主键的一对一的映射,单向的,实例
hibernate映射文件--主键生成策略[参考].pdf
Hibernate 一对一主键单向关联 Hibernate 一对一连接表单向关联 Hibernate 一对多外键单向关联 Hibernate 一对多连接表单向关联 Hibernate 多对一外键单向关联 Hibernate 多对一连接表单向关联 Hibernate 多对多单向...
Hibernate一对一主键映射实例,里面包含源程序,测试程序,映射说明
Hibernate高级映射的几个单向关系,单向一对一(共享主键方式、唯一外键方式),单向多对一,单向一对多,单向多对多。
这个是针对初学Hibernate一对多主键关联映射的源代码 ,希望对初学者有所帮助,开发环境是MyEclipse7.5和HIbernate3.2
:Hibernate有两种映射实体一对一关联关系的实现方式:共享主键方式和唯一外键方式。 共享主键方式: 所谓共享主键方式就是限制两个数据表的主键使用相同的值
博文链接:https://shaqiang32.iteye.com/blog/201309
hibernate主键一对一关联映射代码示例
博文链接:https://llying.iteye.com/blog/220803
hibernate应用[包括示例,映射,主键自增,各种查询操作方式以及配置文档以及Annotation示例]
博文链接:https://llying.iteye.com/blog/220802