标题:[求助]hibernate实例
只看楼主
y19850211
Rank: 4
等 级:贵宾
威 望:12
帖 子:83
专家分:0
注 册:2005-10-2
 问题点数:0 回复次数:3 
[求助]hibernate实例

那位高手 给我点hibernate 的实例来!

主要是分页的,越多实例越好

搜索更多相关主题的帖子: 实例 hibernate 
2006-01-07 13:41
xiao_2008
Rank: 1
等 级:新手上路
帖 子:103
专家分:0
注 册:2006-4-22
得分:0 

package com;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
public abstract class HibernateBase
{
protected SessionFactory sessionFactory;//会话工厂,用于创建会话
protected Session session;//hibernate会话
protected Transaction transaction; //hiberante事务

/**
*开始一个hibernate事务
*/
protected void beginTransaction()
throws HibernateException {
// 帮助方法

session = SessionFactory3.currentSession();
transaction = session.beginTransaction();
}

/**
*结束一个hibernate事务。
*/
protected void endTransaction(boolean commit)
throws HibernateException {

if (commit) {
transaction.commit();
} else {
//如果是只读的操作,不需要commit这个事务。
transaction.rollback();
}
SessionFactory3.closeSession();
}
}

package com;

import org.hibernate.*;
import java.util.*;

import org.hibernate.Query;
import com.HibernateBase;
import org.hibernate.HibernateException;
import vo.customervo;
public class Dao extends HibernateBase{

public Dao() {
super();
// TODO Auto-generated constructor stub
}

/**
* @param args
*/
public void getCustomer() {
session = SessionFactory3.currentSession();
Query query = session.createQuery("from customervo as a");
//List list = query.list();
Iterator it = query.iterate();
while (it.hasNext()) {
customervo temp = (customervo) it.next();
System.out.println(" " + temp.getCustomerId()+" "+temp.getCustomerName()+" "+temp.getCustomerAge()+" "+temp.getCustomerBirth());

}
SessionFactory3.closeSession();//
}
//按那个ID 更新
public void upadaCustomter(String id)
{ beginTransaction();
customervo Customer=(customervo)session.load(customervo.class,id);
Customer.setCustomerName("panxi");
Customer.setCustomerAge(new Long(50));
Customer.setCustomerBirth(new Date(2005-05-06));
session.save(Customer);
endTransaction(true);

}
/**
*删除给定ID的course
*/
public void deleteCustomer(String customerID)throws HibernateException
{
beginTransaction();
customervo customer=(customervo)session.load(customervo.class,customerID);
session.delete(customer);
endTransaction(true);
}

/**
/**
*增加一个Course
*/
public void addCustomer(customervo st)throws HibernateException
{
beginTransaction();
session.save(st);
endTransaction(true);
}


public static void main(String[] args) {
// TODO Auto-generated method stub

Dao dao=new Dao();
dao.getCustomer();
dao.upadaCustomter("3");
System.out.println("更新以后: ");
dao.getCustomer();

customervo temp=new customervo();
temp.setCustomerId("009");
temp.setCustomerAge(new Long(100));
temp.setCustomerName("xiao");
temp.setCustomerBirth(new Date(2006-01-22));
dao.addCustomer(temp);
System.out.println("添加的以后: ");
dao.getCustomer();

dao.deleteCustomer("009");
System.out.println("删除以后: ");
dao.getCustomer();

}

}


看动画片
2006-05-26 13:37
tangzhi
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-21
得分:0 

java.rmi.ConnectException: Connection refused to host: 134.113.179.6; nested exc
eption is:
java.net.ConnectException: Connection timed out: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:567)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185
)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:101)
at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Sour
ce)
at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvo
kerProxy.java:135)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.jav
a:96)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.
java:46)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:4
5)
at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:173)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
at $Proxy0.create(Unknown Source)
at Client.Cconnect(Client.java:23)
at application.connect_actionPerformed(application.java:395)
at application_connect_actionAdapter.actionPerformed(application.java:45
3)
2006-05-28 18:00
tangzhi
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-21
得分:0 

怎么解决上面这个问题呀
如果知道的放到我邮箱里去,好不?
我的邮箱是tang-20502@163.com

2006-05-28 18:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-41947-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.101349 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved