hibernate HelloWorld

2019-04-15 16:20发布

[img]http://dl.iteye.com/upload/picture/pic/127729/c22ac1af-787a-3336-a4c7-dc2e35273192.png[/img]

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.demo.hibernate.model.TBook;


public class Application {

public static void main(String[] args) {

TBook b=new TBook();
b.setId(100000);
b.setName("book1");
b.setAuthor("author1");
b.setPress("press1");
b.setPrice(23);

Configuration cfg=new Configuration();
SessionFactory factory=cfg.configure().buildSessionFactory();
Session session=factory.openSession();

session.beginTransaction();
session.save(b);
session.getTransaction().commit();

session.close();
factory.close();
}
}


"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">






com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/bookshop
root
123456


1


org.hibernate.dialect.HSQLDialect


thread


org.hibernate.cache.NoCacheProvider


true


update