많은 게시물을 읽었지만 어느 누구도 내 문제에 적합하지 않습니다. 나는 hibernate.cgf.xml을 eclipse의 "src"폴더 밑에 놓았는데, 인터넷에서 예제를 통해 배운 것에 따라. 내 응용 프로그램을 실행할 때파일을 찾을 수 없습니다 : hibernate.cgf.xml
는하지만, 나는이
이 클래스는 응용 프로그램
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
}
관련 코드를 게시하십시오. –
나는 내 게시물을 편집했습니다. – MDP