Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Task {
- private int id;
- private String desc;
- private Timestamp create;
- private boolean done;
- //гетеры и сеттеры...
- }
- <?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>
- <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>
- 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();
- 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)
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement