netbean 的 hibernateUtil 类编写的问题

最近刚用netbean5.5   ,下载了   hibernate   插件。

项目目录   :   缺省包
                                -----Main.java
                                ---Student.hbm.xml
                            -----hibernamte.cfg.xml
                    model
                            -----Student.java
                    persistence
                            -----DAOImp.java
                            -----HibernateUtil.java

其中   如果用   hibernate插件   自动生成   HibernateUtil.java的话,代码如下
package   persistence;


import   java.io.BufferedReader;
import   java.io.InputStream;
import   java.io.InputStreamReader;
import   java.util.Properties;
import   org.apache.commons.logging.Log;
import   org.apache.commons.logging.LogFactory;
import   org.hibernate.HibernateException;
import   org.hibernate.SessionFactory;
import   org.hibernate.cfg.Configuration;
import   org.hibernate.classic.Session;

/**
  *   @netbeans.hibernate.util
  */
public   class   NewHibernateUtil   {
        private   static   Log   log   =   LogFactory.getLog(NewHibernateUtil.class);
       
        private   static   SessionFactory   sessionFactory;
       
        private   static   SessionFactory   getSessionFactory()   {
                try   {
                        if   (sessionFactory   ==   null)   {
                                Configuration   configuration   =   new   Configuration();
                                //   load   all   beans
                                InputStream   is   =   NewHibernateUtil.class.getResourceAsStream( "hibernateBeans.lst ");
                                BufferedReader   reader   =   new   BufferedReader(new   InputStreamReader(is));
                                String   line   ;
                                while   ((line   =   reader.readLine())   !=   null)   {
                                        configuration.addResource(line);
                                }
                                Properties   properties   =   new   Properties();
                                properties.load(NewHibernateUtil.class.getResourceAsStream( "hibernate.properties "));
                                configuration.setProperties(properties);
                                sessionFactory   =     configuration.buildSessionFactory();
                        }
                       
                }   catch   (Throwable   ex)   {
                        log.error( "Initial   SessionFactory   creation   failed. ",   ex);
                        throw   new   ExceptionInInitializerError(ex);
                }
                return     sessionFactory;
        }
       
        public   static   final   ThreadLocal   session   =   new   ThreadLocal();
       
       
        public   static   Session   currentSession()   throws   HibernateException   {
                Session   s   =   (Session)   session.get();
                if   (s   ==   null)   {
                        s   =   getSessionFactory().openSession();
                        session.set(s);
                }
                return   s;
        }
       
       
        public   static   void   closeSession()   throws   HibernateException   {
                Session   s   =   (Session)   session.get();
                session.set(null);
                if   (s   !=   null)
                        s.close();
        }
}
                但是这样运行时     错误,应该是找不到配置文件
  Caused   by:   java.lang.NullPointerException
                at   java.io.Reader. <init> (Reader.java:61)
                at   java.io.InputStreamReader. <init> (InputStreamReader.java:55)
                at   persistence.NewHibernateUtil.getSessionFactory(NewHibernateUtil.java:30)
                ...   3   more
             
如果用我自己写的   HibernateUtil.java

/*
  *   HibernateUtil.java
  *  
  *   Created   on   2007-10-26,   19:24:48
  *  
  *   To   change   this   template,   choose   Tools   ¦   Templates
  *   and   open   the   template   in   the   editor.
  */

package   persistence;
import   org.hibernate.HibernateException;
import   org.hibernate.Session;
import   org.hibernate.SessionFactory;
import   org.hibernate.cfg.Configuration;
/**
  *
  *   @author   Administrator
  */
public   class   HibernateUtil   {

        public   HibernateUtil()   {
             
        }
          private   static   final   SessionFactory   sessionFactory;
                static   {
                        try
                        {
                              sessionFactory=new   Configuration().configure().buildSessionFactory();
                           
                        }
                        catch(HibernateException   ex)
                        {
                                throw   new   RuntimeException( "Exception   building   SessionFactory "+ex.getMessage(),ex);
                        }
                }
                public   static   Session   currentSession()   throws   HibernateException   {
                        Session   s=sessionFactory.openSession();
                        return   s;
                }
                public   static   void   closeSession(Session   s)
                {
                        if(s!=null)
                                s.close();
                }
       
}


则可以运行,哪位能够帮我看下这是为什么?谢谢  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 NetBeans 编写 CSS 登录页面的示例代码: HTML 代码: ```html <!DOCTYPE html> <html> <head> <title>Login Page</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="login-box"> <h2>Login Here</h2> <form> <p>Username</p> <input type="text" name="" placeholder="Enter Username"> <p>Password</p> <input type="password" name="" placeholder="Enter Password"> <input type="submit" name="" value="Login"> <a href="#">Forgot Password</a> </form> </div> </body> </html> ``` CSS 代码: ```css body { margin: 0; padding: 0; background: #f2f2f2; } .login-box { width: 320px; height: 420px; background: #fff; color: #000; top: 50%; left: 50%; position: absolute; transform: translate(-50%, -50%); box-sizing: border-box; padding: 70px 30px; } h2 { margin: 0; padding: 0 0 20px; text-align: center; font-size: 22px; } .login-box p { margin: 0; padding: 0; font-weight: bold; } .login-box input { width: 100%; margin-bottom: 20px; } .login-box input[type="text"], .login-box input[type="password"] { border: none; border-bottom: 1px solid #000; background: transparent; outline: none; height: 40px; color: #000; font-size: 16px; } .login-box input[type="submit"] { border: none; outline: none; height: 40px; background: #000; color: #fff; font-size: 18px; border-radius: 20px; } .login-box input[type="submit"]:hover { cursor: pointer; background: #ffc107; color: #000; } .login-box a { text-decoration: none; font-size: 14px; line-height: 20px; color: darkgrey; } .login-box a:hover { color: #ffc107; } ``` 将以上两个代码复制到 NetBeans 中,然后保存为 `index.html` 和 `style.css`。然后在浏览器中打开 `index.html` 文件,你就可以看到一个简单的 CSS 登录页面了。 希望这个示例可以帮助你开始在 NetBeans 中编写 CSS 代码!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值