Guest User

Untitled

a guest
Jan 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  3.  
  4. <hibernate-configuration>
  5. <session-factory>
  6. <property name="hibernate.connection.driver_class">org.sqlite.JDBC</property>
  7. <property name="hibernate.connection.url">jdbc:sqlite:stuff.db</property>
  8. <property name="hibernate.dialect">com.enigmabridge.hibernate.dialect.SQLiteDialect</property>
  9. <property name="hibernate.hbm2ddl.auto">create</property>
  10. <property name="hibernate.show_sql">true</property>
  11. <mapping resource="stuff/Stuff.hbm.xml"/>
  12.  
  13. </session-factory>
  14. </hibernate-configuration>
  15.  
  16. package stuff;
  17.  
  18. public class Stuff {
  19. private Integer id;
  20. private String stuff;
  21.  
  22. public Stuff() {
  23. }
  24.  
  25. public Stuff(String stuff) {
  26. this.stuff = stuff;
  27. }
  28.  
  29. public Integer getId() {
  30. return id;
  31. }
  32.  
  33. public void setId(Integer id) {
  34. this.id = id;
  35. }
  36.  
  37. public String getStuff() {
  38. return stuff;
  39. }
  40.  
  41. public void setStuff(String stuff) {
  42. this.stuff = stuff;
  43. }
  44.  
  45. @Override
  46. public String toString() {
  47. return "Stuff{" + "id=" + id + ", stuff=" + stuff + '}';
  48. }
  49.  
  50. }
  51.  
  52. <hibernate-mapping>
  53. <class name="stuff.Stuff" table="stuff">
  54. <id name="id" type="integer" column="id">
  55. <generator class="increment"/>
  56. </id>
  57. <property name="stuff" type="string" column="stuff"/>
  58.  
  59. </class>
  60. </hibernate-mapping>
  61.  
  62. package stuff;
  63.  
  64. import java.util.List;
  65. import org.hibernate.Query;
  66. import org.hibernate.Session;
  67.  
  68. public class Main {
  69.  
  70. public static void main(String[] args) {
  71. Session session = HibernateUtil.getSessionFactory().openSession();
  72. session.beginTransaction();
  73. session.save(new Stuff("blah blah"));
  74.  
  75. //Query q = s.createQuery("select from Stuff");
  76. //List<Stuff> l = q.list();
  77. //for (Stuff s:l)System.out.println(s);
  78. session.getTransaction().commit();
  79. session.close();
  80. System.exit(0);
  81. }
  82.  
  83. }
Add Comment
Please, Sign In to add comment