找不到hibernate.properties

问题描述 投票:1回答:2
  <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找不到错误请回复我为什么会发生

java hibernate jsp
2个回答
0
投票

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

还看到hibernate properties not found


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)或者看看这个answer

© www.soinside.com 2019 - 2024. All rights reserved.