My Task objects should be written to the tasks table:
But I get the error:
Exception in thread "main" org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found: ru.pravvich.model.Task.hbm.xml: origin (ru.pravvich.model.Task.hbm.xml)
That I do not have a mapping, although everything seems to me set up, please help me figure out where I was wrong. Here are all my configurations:
An object:
public class Task { private int id; private String desc; private Timestamp create; private boolean done; //гетеры и сеттеры... } There is a configuration file hibernate.cfg.xml :
<?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="http://www.hibernate.org/xsd/orm/cfg"> <session-factory> <property name="connection.url">jdbc:postgresql://localhost:5432/todo_list</property> <property name="connection.driver_class">org.postgresql.Driver</property> <property name="connection.username">postgres</property> <property name="connection.password">1</property> <property name="dialect">org.hibernate.dialect.PostgreSQL95Dialect</property> <mapping resource="ru.pravvich.model.Task.hbm.xml" /> </session-factory> </hibernate-configuration> There is a file at the corresponding address ru.pravvich.model.Task.hbm.xml :
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping"> <class name="ru.pravvich.model.Task"> <id name="id" column="id"> <generator class="identity" /> </id> <property name="desc" column="description" /> <property name="done" column="done" /> <property name="create" column="create_time" /> </class> </hibernate-mapping> And it lies correctly:
But when you try to run like this:
final SessionFactory factory = new Configuration().configure().buildSessionFactory(); final Session session = factory.openSession(); final Transaction transaction = session.beginTransaction(); final Task task2 = new Task(3, "todo3", new Timestamp(System.currentTimeMillis()), false); session.save(task2); session.close(); factory.close(); And the table:
CREATE TABLE IF NOT EXISTS tasks ( id SERIAL NOT NULL, description TEXT NOT NULL, done BOOLEAN NOT NULL, create_time TIMESTAMP NOT NULL, PRIMARY KEY (id) ); 
<mapping resource="ru/pravvich/model/Task.hbm.xml" />works? - MrFylypenko