1
  <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 错误请回复我为什么会发生

4

2 回答 2

0

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

另请参阅未找到休眠属性

于 2013-07-04T14:36:05.427 回答
0

确保 .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) 或者看到这个答案

于 2013-07-04T14:36:18.720 回答