я только начала изучать hibernate пытаюсь создать проект с использованием hibernate jpa вот файл hibernate.cfg.xml | Код | <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost/Notes_hibernate?useUnicode=true&characterEncoding=UTF-8</property> <property name="connection.username">*</property> <property name="connection.password">*</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="hbm2ddl.auto">update</property> <property name="current_session_context_class">thread</property> <mapping class="notes.model.Note" /> </session-factory> </hibernate-configuration>
|
вот класс, который содержит аннотации | Код | @Entity @Table(name="Events") public class Note {
@Id @Column(name="id") @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @Column(name="name", length=50) private String name; @Column(name="description", length=100) private String description; @Column(name="date") @Temporal(value=TemporalType.TIMESTAMP) private Timestamp dateofevent; @Column(name="type") @Enumerated(EnumType.STRING) private EventType type;
public Note(int id, String name, String description, Timestamp date, EventType type) { this.id = id; this.name = name; this.description = description; this.dateofevent = date; this.type = type; }
//тут еще геттеры и сетторы }
|
вот класс для работы с базой | Код | import java.util.ArrayList; import notes.model.Note; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
public class DBUtils { Configuration cfg = new Configuration().addClass(Note.class); SessionFactory sf = cfg.configure("hibernate.cfg.xml").buildSessionFactory(); public void SaveObject(Note note){ Session sess = sf.openSession(); Transaction t = sess.beginTransaction(); sess.saveOrUpdate(note); t.commit(); sess.close(); } public ArrayList exQuery(String query){ // открываем Session Session sess = sf.openSession();
// поиск, результат в list ArrayList list =(ArrayList) sess.createQuery(query).list();
if (list.size() == 0) { return null; } sess.close(); return list; } }
|
вот, что выдает консоль: | Код | 31 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA 31 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - hibernate.properties not found 31 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist 31 [AWT-EventQueue-0] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling 94 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource: notes/model/Note.hbm.xml 94 [AWT-EventQueue-0] INFO org.hibernate.cfg.Configuration - Reading mappings from resource: notes/model/Note.hbm.xml Exception in thread "AWT-EventQueue-0" org.hibernate.MappingNotFoundException: resource: notes/model/Note.hbm.xml not found at org.hibernate.cfg.Configuration.addResource(Configuration.java:566) at org.hibernate.cfg.Configuration.addClass(Configuration.java:619) at notes.controller.db.DBUtils.<init>(DBUtils.java:21) at notes.controller.Controller.<init>(Controller.java:37) at notes.controller.Controller$6.run(Controller.java:283) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEvent(EventQueue.java:597) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
|
как я понимаю, несмотря на то, что я использую аннотации, hibernate пытается найти файлы маппинга... ну и, само собой, их не находит... что я делаю не так?
|