Advertisement
Guest User

Untitled

a guest
Jan 7th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. import com.fasterxml.classmate.AnnotationConfiguration;
  2. import org.hibernate.HibernateException;
  3. import org.hibernate.Session;
  4. import org.hibernate.SessionFactory;
  5.  
  6. import java.util.Properties;
  7.  
  8. /**
  9. * Created by Developer on 1/7/17.
  10. */
  11. public class GrizzlyHelper {
  12. private static final SessionFactory concreteSessionFactory;
  13. static {
  14. try {
  15. Properties prop = new Properties();
  16. prop.setProperty("hibernate.connection.url", "jdbc:mysql://192.168.0.101:3306/go");
  17. prop.setProperty("hibernate.connection.username", "go");
  18. prop.setProperty("hibernate.connection.password", "go");
  19. prop.setProperty("dialect", "org.hibernate.dialect.MySQLDialect");
  20.  
  21. prop.setProperty("hibernate.hbm2ddl.auto", "create");
  22.  
  23. concreteSessionFactory = new org.hibernate.cfg.Configuration()
  24. .addProperties(prop)
  25. //.addPackage("com.kat")
  26. .addAnnotatedClass(Vehicle.class)
  27. .buildSessionFactory()
  28. ;
  29. }
  30. catch (Exception ex) {
  31. throw new ExceptionInInitializerError(ex);
  32. }
  33. }
  34. public static Session getSession() throws HibernateException {
  35. return concreteSessionFactory.openSession();
  36. }
  37.  
  38. }
  39.  
  40.  
  41.  
  42. /*
  43. import javax.persistence.*;
  44.  
  45. @Entity
  46. @Table(name = "vehicle")
  47. public class Vehicle {
  48. @Id
  49. @GeneratedValue
  50. private int id;
  51.  
  52. @Column(name="plateno")
  53. private String plate;
  54.  
  55. public int getId() {
  56. return id;
  57. }
  58.  
  59. public void setId(int id) {
  60. this.id = id;
  61. }
  62.  
  63. public String getPlate() {
  64. return plate;
  65. }
  66.  
  67. public void setPlate(String plate) {
  68. this.plate = plate;
  69. }
  70. }
  71. */
  72.  
  73.  
  74. /*
  75. import org.hibernate.Session;
  76. import java.util.List;
  77.  
  78. public class Grizzly {
  79. public static void main(String[] args) {
  80. Session sess = GrizzlyHelper.getSession();
  81. sess.beginTransaction();
  82. List<Vehicle> lstVeh = sess.createCriteria(Vehicle.class).list();
  83. System.out.println(lstVeh.size());
  84. sess.close();
  85. }
  86. }
  87. */
  88.  
  89.  
  90. /*
  91. <dependency>
  92. <groupId>org.hibernate</groupId>
  93. <artifactId>hibernate-core</artifactId>
  94. <version>5.2.5.Final</version>
  95. </dependency>
  96. <dependency>
  97. <groupId>mysql</groupId>
  98. <artifactId>mysql-connector-java</artifactId>
  99. <version>6.0.5</version>
  100. </dependency>
  101. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement