Ich versuche, ein Beispiel-Hibernate-Programm zu erstellen, habe ich Arbeitscode von xml-basierten Hibernate-Konfigurationen so versucht, es in Annotation und Java-Konfiguration zu konvertieren. Ich habe Employee.hbm.xml erfolgreich in Annotation umgewandelt (@Entity in Employee.class), aber nicht in der Lage, dies für Hibernate.cfg.xml zu tun.hibernate.cfg.xml zu Java-Konfiguration
Configuration cfg = new AnnotationConfiguration().addAnnotatedClass(com.hibernate.apple.Employee.class);
cfg.setProperty("hibernate.hbm2ddl.auto","update");
cfg.setProperty("hibernate.connection.driver_class","com.mysql.jdbc.Driver");
cfg.setProperty("hibernate.dialect","org.hibernate.dialect.MySQLDialect");
cfg.setProperty("hibernate.connection.url","jdbc:mysql://localhost/DataBase");
cfg.setProperty("hibernate.connection.username","xxx");
cfg.setProperty("hibernate.connection.password","xxx");
Session s = cfg.configure().buildSessionFactory().openSession();
Transaction t = s.beginTransaction();
t.begin();
....
aber sein giving Fehler
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
obigen Code ist die hibernate.hbm.xml zu ersetzen, dann, warum es für die gleiche fragt, ich etwas fehlt bin ?.