刚学hibernate,入门程序搞了快一天了都没有搞定;
请问hibernate.cfg.xml应该防在WEB-INF\classes下还是可以放在WEB-INF\classes下的包里面啊。
相应的某个具体配置文件User.hbm.xml User.java需要放在和hibernate.cfg.xml一去吗?我尝试了很多地方,可是都没有成功。
我是在com\yourcompany\struts\action下的LoginAction中访问的
主要代码如下:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
String name=loginForm.getName();
String password=loginForm.getPassword();
try{

SessionFactory sf=new Configuration().configure().buildSessionFactory();
Session session=sf.openSession();
Transaction tx=session.beginTransaction();
String sql="select * form admin where name='"+name+"'";
Query myquery=session.createSQLQuery(sql);
ArrayList userlist=(ArrayList)myquery.list();
tx.commit();
session.close();
User user=new User();
if((null!=userlist)&&(userlist.size()>0))
{
user=(User)userlist.get(0);
if(!user.getPassword().equals(password))
{
return mapping.findForward("failure");
}
}else
{
return mapping.findForward("failure");
  }

}catch(HibernateException e)
{
System.out.print(e.getMessage());
return mapping.findForward("failure");
   }
return mapping.findForward("success");
}在线等待!

解决方案 »

  1.   

    hibernate.cfg.xml放哪儿都可以
    User.hbm.xml和User.java应该放一起   而不一定和hibernate.cfg.xml放一起
      

  2.   

    随便放在哪
    SessionFactory sf=new Configuration().configure().buildSessionFactory();
    都可以自动加载到吗?
      

  3.   

    放在哪里不是问题,重要的是要在相应的文件中做配置,通常实在stuts-config.xml中配置,否则找不到相关的文件。
      

  4.   

    我说的是hibernate.cfg.xml,程序永远是一环扣一环的,及时层分的很细,要找到某个文件或是配置都是有联系的。
      

  5.   

    都放到src下面
       最直接的方法 ~