Hibernate的配置
来源:互联网 发布:手写文字图片制作软件 编辑:程序博客网 时间:2024/05/20 08:25
1.在 Src 目录下
hibernate.cfg.xml
<?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>
<property name="show_sql">true</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/test</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
123456
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<mapping resource="hibernate3/object/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
2.Person.hbm.xml 在Person.java包下
<?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>
<property name="show_sql">true</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/test</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
123456
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<mapping resource="hibernate3/object/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
3.所需要的Java包
antlr-2.7.2.jar
commons-collections-3.2.2.jar
commons-logging-1.1.3.jar
dom4j-1.6.1.jar
hibernate3.jar
javassist-3.11.0.GA.jar
jta-1.1.jar
mysql-connector-java-5.1.30-bin.jar
slf4j-api-1.7.12.jar
4.实例代码
package hibernate3.object;
import java.io.File;
import java.util.Iterator;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class FirstHibernate {
public static void main(String[] args) {
Configuration configuration=new Configuration().configure("hibernate.cfg.xml");
SessionFactory sessionFactory=configuration.buildSessionFactory();
Person person=new Person();
person.setName("neo");
person.setAge("20");
Session session=sessionFactory.openSession();
Transaction transaction=session.beginTransaction();
session.save(person);
transaction.commit();
System.out.println("新增加人员成功");
Object pObject=session.get(Person.class, "1");
System.out.println(pObject);
session.close();
sessionFactory.close();
File file=new File("C:\\JavaProject\\FirstHibernate\\WebContent\\WEB-INF\\lib");
File[] LIST=file.listFiles();
for (File file2 : LIST) {
System.out.println(file2.getName());
}
}
}
- hibernate-hibernate的配置
- hibernate配置的原因?
- Hibernate的配置
- hibernate的unique配置
- Hibernate的配置信息
- hibernate二级缓存的配置
- hibernate的Annotation配置
- hibernate c3p0的配置
- hibernate二级缓存的配置
- Hibernate的配置
- MyEclipse的Hibernate配置
- hibernate的配置
- spring+hibernate的配置
- hibernate的配置详解
- Hibernate的具体配置
- hibernate.cfg的配置
- hibernate的二级缓存配置
- hibernate的具体配置
- 第三方开源库:ListView相关:滑动删除
- k20+caffe+cuda 7.5+cudnn v5+python
- JM8.6之get_block() 1/4亮度像素内插详述
- 常用组件之侧栏菜单滑动及返回顶部效果
- javaweb学习总结——使用JDBC处理MySQL大数据
- Hibernate的配置
- Maven入门1
- JAVA WEB基础- DBUtils
- Run script only when installing勾选后 未知的Crash问题
- 网络爬虫-网页源码的gzip压缩和解压
- typedef详细
- 蓝牙核心技术概述(二):蓝牙使用场景
- 关于level_idc
- Airpal 部署文档