<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/bookshop</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping class="com.demo.hibernate.model.T_Book" />
</session-factory>
</hibernate-configuration>
package com.demo.hibernate.model;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class T_Book {
private int id;
private String name;
private String author;
private String press;
private double price;
@Id
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPress() {
return press;
}
public void setPress(String press) {
this.press = press;
}
public double getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.demo.hibernate.model.T_Book;
public class Application {
public static void main(String[] args) {
T_Book b=new T_Book();
b.setId(100002);
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 Annotations API 中文文档 前言 1. 创建一个注解项目 1.1. 系统需求 1.2. 系统配置 2. 实体Bean 2.1. 简介 2.2. 用EJB3注解进行映射 2.2.1. 声明实体bean 2.2.1.1. 定义表(Table) 2.2.1.2. 乐观...
现在已经不用*.hbm.xml这种映射文件了,都是用Annotation(注解)方式来完成实体与表之间的映射关系,这样看起来比用xml文件来映射更具有可读性,自我感觉以后Hibernate Annotation的映射方式将代替hibernate 的*....
webwork2.1.7 中文开发文档 Hibernate Annotations参考文档-3.20中文开发文档 Hibernate_3.2.0_Reference_zh_CN中文开发文档
hibernate annotations 中文参考手册
Hibernate Annotations 中文版
hibernate-annotations-3.4.0.GA hibernate-annotations-3.4.0.GA hibernate-annotations-3.4.0.GA
hibernate annotations 3.4.0.GA API
hibernate annotations 的中文帮助文档 可以帮您更好的学习hibernate 的注解配置
Hibernate Annotations 3.5.6-Final 全英文版
Hibernate Annotations API英文版,CHM格式
hibernate annotations
Hibernate Annotations参考文档-3.20MSN---zhoujianguo_leo@hotmail.com
hibernate 和hibernate_annotations(中文API)帮助文档。
详细介绍了hibernate annotations的使用,非常不错的一本书,不敢独享,只能拿出来了。
Hibernate annotations大全
Hibernate Annotation参考手册
hibernate-annotations-3.4.0