临时表,这怎么可能~~~~~有谁懂Hibernate机制的?

解决方案 »

  1.   

    这不是hibernate的问题,是你的JSP页面缓存问题。每个JSP按如下修改:
    <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>
      

  2.   

    “感觉这个HibernateSessionFactory 写得有问题”--同意import net.sf.hibernate.HibernateException;
    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);
    }
    }}
      

  3.   

    public class PersistentSession { private static Log log =
    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);
    }
    }}
      

  4.   

    public class PersistentTransaction { private static Log log = LogFactory.getLog(PersistentTransaction.class); private Transaction tran; /**
     * 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);
    }
    }}