Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication4;
- import javax.transaction.Transaction;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.cfg.Configuration;
- /**
- *
- * @author student
- */
- public class JavaApplication4 {
- public static void main(String[] args) {
- Configuration configuration = new Configuration().
- setProperty("connection.driver_class","com.mysql.jdbc.Driver").
- setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/hibernate").
- setProperty("hibernate.connection.username", "root").
- setProperty("hibernate.connection.password", "").
- setProperty("dialect", "org.hibernate.dialect.MySQLDialect").
- setProperty("hibernate.hbm2ddl.auto", "update").
- addAnnotatedClass(Student.class);
- SessionFactory factory = configuration.buildSessionFactory();
- Session session = factory.openSession();
- org.hibernate.Transaction transaction = session.beginTransaction();
- Student student1= new Student ("Adam", "Kosa", 1234);
- Student student2= new Student ("Kamil", "Sawes", 1233);
- Student student3 = new Student();
- session.save(student1);
- session.save(student2);
- session.save(student3);
- transaction.commit();
- session.close();
- factory.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement