【问题标题】:hibernate.properties not foundhibernate.properties 未找到
【发布时间】:2013-07-02 14:31:39
【问题描述】:
  <form action="register.jsp" method="post">
id:<input type="text" name="id"/><br><br/>
Name:<input type="text" name="name"/><br><br/>
Password:<input type="password" name="password"/><br><br/>
Email ID:<input type="text" name="email"/><br><br/>
<input type="submit" value="register"/>

</form>

上面的文件是index.jsp

<%@page import="com.javatpoint.mypack.UserDao"%>
<jsp:useBean id="obj" class="com.javatpoint.mypack.User"></jsp:useBean>
<jsp:setProperty property="*" name="obj"/>
<%
obj.setName(request.getParameter("name"));
obj.setPassword(request.getParameter("password"));
obj.setEmail(request.getParameter("email"));
try
{
System.out.println("--------->"+obj.getName());

int i=UserDao.register(obj);
if(i>0)
{
out.print("You are successfully registered");
}
else
{
    out.print("registration failed");
}
}
catch(Exception e)
{

    out.print("You are not registered");
}
%>

上面的文件是register.jsp

package com.javatpoint.mypack;

public class User {
public int id;
public String name,password,email;

public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
}


}

上面的文件是user.java

package com.javatpoint.mypack;


import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.*;

public class UserDao {

    public static int register(User u){
        int i=0;
        try{

        Session session=new Configuration().configure().buildSessionFactory().openSession();

        Transaction t=session.beginTransaction();
        t.begin();

        i=(Integer)session.save(u);

        t.commit();
        session.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }

}

上面的程序是UserDao.java 执行应用程序时出现 hibernate.properties not found 错误 请回复我为什么会这样

【问题讨论】:

    标签: java hibernate jsp


    【解决方案1】:

    确保 .properties 文件位于类路径的根目录中,这意味着如果你有类似的东西

    --src //source folder which all files in it will be compiled/copied to deployment
       --user   //those are folders which has classes in it
       --dao    //those are folders which has classes in it
      hibernate.properties //should be here
    

    如果它在结构之上,那么new Configuration().configure() 应该会自动找到它,或者如果你不想把它放在那里,那么你可以执行以下操作: new Configuration().configure(path) 或者看这个answer

    【讨论】:

    • 我按照你说的执行了上面的程序,但即使它显示相同的错误。如果在 jsp 上有任何示例程序作为前端并休眠作为后端请发布链接
    【解决方案2】:

    默认情况下,Hibernate 在启动时会查找 hibernate.properties 和 hibernate.cfg.xml 并在未找到时记录调试消息。所以禁用休眠的调试/信息,你将看不到消息。见http://forum.springsource.org/showthread.php?127317-hibernate-properties-with-JavaConfig

    另见hibernate properties not found

    【讨论】:

      猜你喜欢
      • 2011-06-12
      • 2017-01-26
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-05
      • 1970-01-01
      相关资源
      最近更新 更多