Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 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://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  3. <hibernate-configuration>
  4. <session-factory>
  5. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  6. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  7. <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/itaprojekat?zeroDateTimeBehavior=convertToNull</property>
  8. <property name="hibernate.connection.username">root</property>
  9. <property name="hibernate.connection.password">2007991710126</property>
  10. <property name="hibernate.connection.autocommit">true</property>
  11. <property name="hibernate.show_sql">true</property>
  12. <property name="hibernate.hbm2ddl.auto">update</property>
  13. <mapping class="itaprojekat.Kategorija"></mapping>
  14. </session-factory>
  15. </hibernate-configuration>
  16.  
  17. public class HibernateUtil {
  18. private static Session sesija = null;
  19. public static Session getSession(){
  20. if(sesija==null){
  21. Configuration cfg = new Configuration();
  22. cfg.configure("/config/hibernate.cfg.xml");
  23. ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
  24. SessionFactory sessionFactory = cfg.buildSessionFactory(serviceRegistry);
  25. sesija = sessionFactory.openSession();
  26. }
  27. return sesija;
  28. }
  29. }
  30.  
  31. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  32. Session sesija = HibernateUtil.getSession();
  33. sesija.beginTransaction();
  34. InputContext ic = tfNaziv.getInputContext(); //tfNaziv is my textfield
  35. Kategorija k = new Kategorija();
  36. k.setNaziv(ic);
  37. sesija.save(k);
  38. sesija.getTransaction().commit();
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement