Hibernate 入门
来源:互联网 发布:开淘宝店应该注意什么 编辑:程序博客网 时间:2024/06/16 18:18
hibernate 并不是只有在web项目中才使用,在初学时,可以直接在Java 项目里学习。
4.1.10final版本 配置以及需要的jar文件
配置文件从手册中拷贝
将所需要加注解的类交给hibernate知道。用mapping配置。
所需要的jar包
hibernate的requry包
mysql的连接包
单元测试包
<?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/bbs</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<!-- <property name="connection.pool_size">1</property> -->
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</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.internal.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 resource="org/hibernate/tutorial/domain/Event.hbm.xml"/> -->
<mapping class="cn.njupt.model.Student"/>
</session-factory>
</hibernate-configuration>
注解实体
public class Student
{
private int id;
private String name;
private String profession;
@Id @GeneratedValue
@Column(name="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 getProfession()
{
return profession;
}
public void setProfession(String profession)
{
this.profession = profession;
}
}
- Hibernate 入门
- Hibernate 入门
- Hibernate入门
- Hibernate入门
- Hibernate入门
- Hibernate 入门
- Hibernate入门
- Hibernate入门
- Hibernate 入门
- Hibernate入门
- Hibernate入门
- Hibernate入门
- Hibernate入门
- Hibernate入门
- Hibernate入门
- hibernate 入门
- Hibernate入门
- hibernate入门
- android基础学习总结
- Web测试自动化资料
- Hometask--codeForces 214B
- hibernate第一天
- 在Spring3中,配置DataSource的方法
- Hibernate 入门
- Zygote进程功能笔记
- Java 继承加载顺序 以及 多态中变量和方法
- 关于Linux操作系统的开机过程详解
- Java Socket实战之三 传输对象
- 消息模式Toast.makeText用法
- SSH服务器登录慢的解决办法
- Intellij IDEA常用配置详解
- 功能强大的JS虚拟键盘