Hibernate映射文件

new_starts 2007-09-09 10:26:19
我映射文件和持久化类是自动生成的
<?xml version="1.0" encoding="utf-8"?>
<!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 Persistence Tools
-->
<hibernate-mapping>
<class name="com.Request" table="request" schema="callback" catalog="callback">
<composite-id name="id" class="com.RequestId">
<key-property name="id" type="long">
<column name="id" />
</key-property>
<key-property name="acctId" type="string">
<column name="AcctId" length="40" />
</key-property>
<key-property name="primaryphone" type="string">
<column name="primaryphone" length="50" />
</key-property>
<key-property name="bundlephone1" type="string">
<column name="bundlephone1" length="50" />
</key-property>
<key-property name="bundlephone2" type="string">
<column name="bundlephone2" length="50" />
</key-property>
<key-property name="numcard" type="integer">
<column name="numcard" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>



Request类
public class Request implements java.io.Serializable {


// Fields

private RequestId id;


// Constructors

/** default constructor */
public Request() {
}


/** full constructor */
public Request(RequestId id) {
this.id = id;
}




public RequestId getId() {
return this.id;
}

public void setId(RequestId id) {
this.id = id;
}
}
RequestId类

public class RequestId implements java.io.Serializable {


// Fields

private long id;
private String acctId;
private String primaryphone;
private String bundlephone1;
private String bundlephone2;
private Integer numcard;


// Constructors

/** default constructor */
public RequestId() {
}


/** full constructor */
public RequestId(long id, String primaryphone, String bundlephone1, String bundlephone2, Integer numcard) {
this.id = id;
this.requesttype = requesttype;
this.primaryphone = primaryphone;
this.bundlephone1 = bundlephone1;
this.bundlephone2 = bundlephone2;
this.numcard = numcard;
}


// Property accessors

public long getId() {
return this.id;
}

public void setId(long id) {
this.id = id;
}


public String getAcctId() {
return this.acctId;
}

public void setAcctId(String acctId) {
this.acctId = acctId;
}


public String getPrimaryphone() {
return this.primaryphone;
}

public void setPrimaryphone(String primaryphone) {
this.primaryphone = primaryphone;
}

public String getBundlephone1() {
return this.bundlephone1;
}

public void setBundlephone1(String bundlephone1) {
this.bundlephone1 = bundlephone1;
}

public String getBundlephone2() {
return this.bundlephone2;
}

public void setBundlephone2(String bundlephone2) {
this.bundlephone2 = bundlephone2;
}

public Integer getNumcard() {
return this.numcard;
}

public void setNumcard(Integer numcard) {
this.numcard = numcard;
}
}

测试类为
public static void main(String[] args) {
Session session =HibernateSessionFactory.getSession();

String hql="from Request request";
System.out.println(hql);
Query query=session.createQuery(hql);

List list=query.list();

Iterator it=list.iterator();
int k=0;
while(it.hasNext()){
Object obj=(Object)it.next();
Request request=(Request)obj;

k=k+1;
System.out.println('K="+k);
if(request !=null){
RequestId requestid=request.getId();
System.out.println(requestid.getBundlephone1()+"\t"+requestid.getBundlephone2()+"\t"+
"课程:"+requestid.getBundlephone2());
}else{
System.out.println("没数据null");
}
}
}

运行结果为:
K=2
没数据null


(说明:数据库中是有数据的,但不知道为什么会打印"没数据null")




...全文
189 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
longkas 2007-10-15
  • 打赏
  • 举报
回复
bangding le
awusoft 2007-10-15
  • 打赏
  • 举报
回复
查询不需要事务的吧?
iskyshop 2007-10-14
  • 打赏
  • 举报
回复
Session   session   =HibernateSessionFactory.getSession();  
String hql="from Request AS request"; (加上AS)
System.out.println(hql);
Transaction transaction=session.beginTransaction();
Query query=session.createQuery(hql);
list=query.list();
session.flush();
tx.commit();
kobe_bryant 2007-10-14
  • 打赏
  • 举报
回复
Session session =HibernateSessionFactory.getSession();
String hql="from Request AS request"; (加上AS)
System.out.println(hql);
Transaction transaction=session.beginTransaction();
Query query=session.createQuery(hql);
list=query.list();
session.flush();
tx.commit();
xiyuan1999 2007-10-14
  • 打赏
  • 举报
回复
String hql="from Request as request";

yztommyhc 2007-10-14
  • 打赏
  • 举报
回复
运行结果怎么没有 K=1 的时候呢?
lindazch 2007-09-10
  • 打赏
  • 举报
回复
帮顶
zjf405 2007-09-10
  • 打赏
  • 举报
回复
K=2证明有数据啊,不知道楼主是什么问题
在List list=query.list();后面加上 session.flush();

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧