2014-10-06 5 views
0

많은 게시물을 읽었지만 어느 누구도 내 문제에 적합하지 않습니다. 나는 hibernate.cgf.xml을 eclipse의 "src"폴더 밑에 놓았는데, 인터넷에서 예제를 통해 배운 것에 따라. 내 응용 프로그램을 실행할 때파일을 찾을 수 없습니다 : hibernate.cgf.xml

는하지만, 나는이

enter image description here

이 클래스는 응용 프로그램

public class TestHibernateInsert { 
    public static void main(String[] args) 
    { 
     Session session = HibernateUtil.getSessionFactory().openSession(); 
     session.beginTransaction(); 

     //Add new Employee object 
     EmployeeEntity emp = new EmployeeEntity(); 
     emp.setEmail("[email protected]"); 
     emp.setNome("Nome"); 
     emp.setCognome("Cognome"); 
     emp.setPassword("Password"); 

     //Save the employee in database 
     session.save(emp); 

     //Commit the transaction 
     session.getTransaction().commit(); 
     HibernateUtil.shutdown(); 
    } 
} 

를 시작 내 웹 응용 프로그램입니다 "could not find file: hibernate.cgf.xml"

오류를 얻을 STIL 이것은 SessionFactory 클래스입니다

public class HibernateUtil 
    { 
     private static final SessionFactory sessionFactory = buildSessionFactory(); 

     private static SessionFactory buildSessionFactory() 
     { 
      try 
      { 
       // Create the SessionFactory from hibernate.cfg.xml 
       return new AnnotationConfiguration().configure(new File("hibernate.cgf.xml")).buildSessionFactory(); 
      } 
      catch (Throwable ex) { 
       // Make sure you log the exception, as it might be swallowed 
       System.err.println("Initial SessionFactory creation failed." + ex); 
       throw new ExceptionInInitializerError(ex); 
      } 
     } 

     public static SessionFactory getSessionFactory() { 
      return sessionFactory; 
     } 

     public static void shutdown() { 
      // Close caches and connection pools 
      getSessionFactory().close(); 
     } 
    } 

이 당신이 Eclipse를 사용하여 웹 응용 프로그램을 개발 한 것 영구 객체 클래스

Entity 
@Table(name = "utente") 
public class EmployeeEntity implements Serializable{ 

    private static final long serialVersionUID = -1798070786993154676L; 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "id", unique = true, nullable = false) 
    private Integer id; 

    @Column(name = "email", unique = true, nullable = false, length = 100) 
    private String email; 

    @Column(name = "nome", unique = false, nullable = false, length = 100) 
    private String nome; 

    @Column(name = "cognome", unique = false, nullable = false, length = 100) 
    private String cognome; 

    @Column(name = "password", unique = false, nullable = false, length = 100) 
    private String password; 

    public Integer getId() { 
     return id; 
    } 

    public void setId(Integer id) { 
     this.id = id; 
    } 

    public String getEmail() { 
     return email; 
    } 

    public void setEmail(String email) { 
     this.email = email; 
    } 

    public String getNome() { 
     return nome; 
    } 

    public void setNome(String nome) { 
     this.nome = nome; 
    } 

    public String getCognome() { 
     return cognome; 
    } 

    public void setCognome(String cognome) { 
     this.cognome = cognome; 
    } 

    public String getPassword() { 
     return password; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 

    //Getters and setters 

} 
+1

관련 코드를 게시하십시오. –

+0

나는 내 게시물을 편집했습니다. – MDP

답변

0

입니다. 기본적으로 최대 절전 모드는 클래스 경로의 루트에있는 hibernate.cfg.xml 파일을 찾습니다.

마지막으로 파일은 웹 응용 프로그램의 클래스 경로의 루트 인 WEB-INF/classes 디렉토리에 있어야합니다.

+0

시도했지만 동일한 오류가 발생했습니다. – MDP

+0

@MatteoDepasquali, 질문을 편집하고 파일이있는 위치를 표시 할 수 있습니까? – Chaitanya

+0

시간을 낭비 해 죄송합니다. xml 파일을 WEB-INF/classes에 넣으면 작동합니다. 난 이미 문제를 해결하지 않고 그것을 시도, 아마 그것은 식의 문제가되었습니다. 나는 내 프로젝트를 청소하고 이클립스를 재시작했다. 고마워요 :) – MDP

0

hibernate.cfg.xml

hibernate.cgf.xml에서 파일 이름을 변경하고 HibernateUtil과 클래스에

 private static SessionFactory buildSessionFactory() 
     { 
      try 
      { 
       // Create the SessionFactory from hibernate.cfg.xml 
       return new AnnotationConfiguration().configure().buildSessionFactory(); 
      } 
      catch (Throwable ex) { 
       // Make sure you log the exception, as it might be swallowed 
       System.err.println("Initial SessionFactory creation failed." + ex); 
       throw new ExceptionInInitializerError(ex); 
      } 
     } 
0

당신의 buildSessionFactory() 방법을 변경

을 hibernate.cfg.xml로하는 기존의 설정 파일의 이름을 변경 또는 코드 아래 사용하세요 세션을 만들려면

구성 cfg = new Configuration() ; cfg.configure ("hibernate.cgf.xml");

+0

나는 이미 그것을했지만, 나는 같은 오류가 발생했습니다. – MDP

관련 문제