Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.fasterxml.classmate.AnnotationConfiguration;
- import org.hibernate.HibernateException;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import java.util.Properties;
- /**
- * Created by Developer on 1/7/17.
- */
- public class GrizzlyHelper {
- private static final SessionFactory concreteSessionFactory;
- static {
- try {
- Properties prop = new Properties();
- prop.setProperty("hibernate.connection.url", "jdbc:mysql://192.168.0.101:3306/go");
- prop.setProperty("hibernate.connection.username", "go");
- prop.setProperty("hibernate.connection.password", "go");
- prop.setProperty("dialect", "org.hibernate.dialect.MySQLDialect");
- prop.setProperty("hibernate.hbm2ddl.auto", "create");
- concreteSessionFactory = new org.hibernate.cfg.Configuration()
- .addProperties(prop)
- //.addPackage("com.kat")
- .addAnnotatedClass(Vehicle.class)
- .buildSessionFactory()
- ;
- }
- catch (Exception ex) {
- throw new ExceptionInInitializerError(ex);
- }
- }
- public static Session getSession() throws HibernateException {
- return concreteSessionFactory.openSession();
- }
- }
- /*
- import javax.persistence.*;
- @Entity
- @Table(name = "vehicle")
- public class Vehicle {
- @Id
- @GeneratedValue
- private int id;
- @Column(name="plateno")
- private String plate;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getPlate() {
- return plate;
- }
- public void setPlate(String plate) {
- this.plate = plate;
- }
- }
- */
- /*
- import org.hibernate.Session;
- import java.util.List;
- public class Grizzly {
- public static void main(String[] args) {
- Session sess = GrizzlyHelper.getSession();
- sess.beginTransaction();
- List<Vehicle> lstVeh = sess.createCriteria(Vehicle.class).list();
- System.out.println(lstVeh.size());
- sess.close();
- }
- }
- */
- /*
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>5.2.5.Final</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>6.0.5</version>
- </dependency>
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement