临时表,这怎么可能~~~~~有谁懂Hibernate机制的?
解决方案 »
- 有没有组队做些项目的,本人学了java一年多,没做过大项目,想跟高手多学点项目经验。
- LINUX下运行JAVA程序????????/
- 关于IDE百思不得其解的几个问题(希望高手解决)
- 输入首页对应的域名,则首页中包含的JSP页就显示无法找到?
- DTO工厂
- 在BufferedInputStream和BufferedOutputStream读写文件的问题
- dom,sax,jdom,jaxp,xerces有什么区别?现在项目要用,不知道选哪个,希望高手指点
- XML的Tab键如何表示
- 求java读写ini文件的源码,先谢了
- JBUILDER 5高手请进,EJB的使用问题。
- 有人用过jrockit 1.4.2加hibernate2.1.6开发吗?
- 刚来报道,请教赋值问题。。。
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body> </body>
</html>
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;public class PersistentSessionFactory { private static Log log = LogFactory.getLog(PersistentSessionFactory.class); private static final SessionFactory sf; static {
try {
Configuration config = new Configuration();
sf = config.configure().buildSessionFactory();
} catch (HibernateException he) {
throw new RuntimeException("Exception building SessionFactory: " + he.getMessage(), he);
}
}
private PersistentSessionFactory() {
} public static PersistentSession getPersistentSession()
throws PersistentSessionException {
try {
Session sess = sf.openSession();
return new PersistentSession(sess);
} catch (HibernateException e) {
System.out.println("HibernateException: " + e);
e.printStackTrace();
log.error(e);
throw new PersistentSessionException(
"Exception getting Session: " + e.getMessage(), e);
}
}}
LogFactory.getLog(PersistentSession.class); private Session sess; PersistentSession(Session sess) {
this.sess = sess;
}
public Session getHibeSession() {
return sess;
} public PersistentTransaction beginTransaction() throws PersistentSessionException {
Transaction tran = null;
try {
tran = sess.beginTransaction();
} catch (HibernateException e) {
throw new PersistentSessionException("During beginTransaction.", e);
}
return new PersistentTransaction(tran);
} /**
* Releases a Connection's database and JDBC resources immediately instead of waiting for them to be automatically released.
*/
public void flush() throws PersistentSessionException {
try {
sess.flush();
} catch (HibernateException e) {
throw new PersistentSessionException("During flush.", e);
}
}
/**
* Releases a Connection's database and JDBC resources immediately instead of waiting for them to be automatically released.
*/
public void close() throws PersistentSessionException {
try {
sess.close();
} catch (HibernateException e) {
throw new PersistentSessionException("During close.", e);
}
}}
* Creates a new instance of TransactImpl using a specified serviceName.
* @param serviceName - service name used to confirm which database will be used
* @throws <{DAOException}>
*/
PersistentTransaction(Transaction tran) {
this.tran = tran;
} /**
* Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by the Connection.
* This method should be used only when auto-commit mode has been disabled.
*/
public void commit() throws PersistentSessionException {
try {
tran.commit();
} catch (HibernateException e) {
log.error("During commit: ", e);
throw new PersistentSessionException(e);
}
} /**
* Drops all changes made since the previous commit/rollback and releases any database locks currently held by this Connection.
* This method should be used only when auto- commit has been disabled.
*/
public void rollback() throws PersistentSessionException {
try {
tran.rollback();
} catch (HibernateException e) {
log.error("During rollback: ", e);
throw new PersistentSessionException(e);
}
}}