那位高手 给我点hibernate 的实例来!
主要是分页的,越多实例越好
----------------解决方案--------------------------------------------------------
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();
}
}
----------------解决方案--------------------------------------------------------
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)
----------------解决方案--------------------------------------------------------
怎么解决上面这个问题呀
如果知道的放到我邮箱里去,好不?
我的邮箱是tang-20502@163.com
----------------解决方案--------------------------------------------------------