Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public class Task {
  2. private int id;
  3. private String desc;
  4. private Timestamp create;
  5. private boolean done;
  6. //гетеры и сеттеры...
  7. }
  8.  
  9. <?xml version="1.0" encoding="utf-8" ?>
  10. <hibernate-configuration xmlns="http://www.hibernate.org/xsd/orm/cfg">
  11. <session-factory>
  12. <property name="connection.url">jdbc:postgresql://localhost:5432/todo_list</property>
  13. <property name="connection.driver_class">org.postgresql.Driver</property>
  14. <property name="connection.username">postgres</property>
  15. <property name="connection.password">1</property>
  16. <property name="dialect">org.hibernate.dialect.PostgreSQL95Dialect</property>
  17.  
  18. <mapping resource="ru.pravvich.model.Task.hbm.xml" />
  19. </session-factory>
  20. </hibernate-configuration>
  21.  
  22. <hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping">
  23. <class name="ru.pravvich.model.Task">
  24. <id name="id" column="id">
  25. <generator class="identity" />
  26. </id>
  27. <property name="desc" column="description" />
  28. <property name="done" column="done" />
  29. <property name="create" column="create_time" />
  30. </class>
  31. </hibernate-mapping>
  32.  
  33. final SessionFactory factory =
  34. new Configuration().configure().buildSessionFactory();
  35.  
  36. final Session session = factory.openSession();
  37.  
  38. final Transaction transaction = session.beginTransaction();
  39. final Task task2 = new Task(3, "todo3",
  40. new Timestamp(System.currentTimeMillis()), false);
  41. session.save(task2);
  42. session.close();
  43. factory.close();
  44.  
  45. CREATE TABLE IF NOT EXISTS tasks (
  46. id SERIAL NOT NULL,
  47. description TEXT NOT NULL,
  48. done BOOLEAN NOT NULL,
  49. create_time TIMESTAMP NOT NULL,
  50. PRIMARY KEY (id)
  51. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement