Skip to content

Instantly share code, notes, and snippets.

@bayraktugrul
Last active September 23, 2018 12:12
Show Gist options
  • Select an option

  • Save bayraktugrul/fd32442a78b6944c451544548e58b966 to your computer and use it in GitHub Desktop.

Select an option

Save bayraktugrul/fd32442a78b6944c451544548e58b966 to your computer and use it in GitHub Desktop.

Revisions

  1. bayraktugrul revised this gist Sep 23, 2018. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions App.java
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,4 @@
    package com.hibernateyazilari.hibernate_2;

    import javax.imageio.spi.ServiceRegistry;

    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
  2. bayraktugrul revised this gist Sep 20, 2018. 1 changed file with 4 additions and 8 deletions.
    12 changes: 4 additions & 8 deletions App.java
    Original file line number Diff line number Diff line change
    @@ -9,15 +9,12 @@

    public class App {


    public static void main( String[] args ) {

    SessionFactory factory = new Configuration()
    .configure("hibernate.cfg.xml")
    .addAnnotatedClass(Student.class)
    .buildSessionFactory();
    .configure("hibernate.cfg.xml")
    .addAnnotatedClass(Student.class)
    .buildSessionFactory();
    Session session = factory.getCurrentSession();

    try {
    Student student = new Student("Tuğrul","Bayrak", "[email protected]");
    session.beginTransaction();
    @@ -26,7 +23,6 @@ public static void main( String[] args ) {

    } finally {
    factory.close();
    }

    }
    }
    }
  3. bayraktugrul created this gist Sep 20, 2018.
    32 changes: 32 additions & 0 deletions App.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    package com.hibernateyazilari.hibernate_2;

    import javax.imageio.spi.ServiceRegistry;

    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.service.internal.SessionFactoryServiceRegistryBuilderImpl;

    public class App {


    public static void main( String[] args ) {

    SessionFactory factory = new Configuration()
    .configure("hibernate.cfg.xml")
    .addAnnotatedClass(Student.class)
    .buildSessionFactory();
    Session session = factory.getCurrentSession();

    try {
    Student student = new Student("Tuğrul","Bayrak", "[email protected]");
    session.beginTransaction();
    session.save(student);
    session.getTransaction().commit();

    } finally {
    factory.close();
    }

    }
    }