hibernate helloworld(xml)
来源:互联网 发布:今日eia数据 编辑:程序博客网 时间:2024/06/18 08:45
首先导入相关的hibernate 包和 mysql的包接着设置映射类接着是映射文件hibernate.hbm.xml:public class Student { private int id; private String name;
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 Student() { super(); // TODO Auto-generated constructor stub }
public Student(int id, String name) { super(); this.id = id; this.name = name; }
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.qi.pojo"> <class name="Student"> <id name="id"></id> <property name="name"></property> </class></hibernate-mapping>
接着是配置文件hibernate.cfg.xml:
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. --><hibernate-configuration>
<session-factory> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property> <property name="connection.username">root</property> <property name="connection.password">root</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <mapping resource="com/qi/pojo/hibernate.hbm.xml"/> </session-factory>
</hibernate-configuration>
接着是text:
import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;
import com.qi.pojo.Student;
public class test1 {public static void main(String[] args) { System.out.println("begin"); Student student=new Student(1,"qi"); Configuration config=new Configuration(); config.configure(); SessionFactory factory=config.buildSessionFactory(); Session session=factory.openSession(); session.beginTransaction(); session.save(student); session.getTransaction().commit(); session.close();}}
- hibernate helloworld(xml)
- Hibernate helloworld xml版本
- hibernate helloworld
- Helloworld!Hibernate
- hibernate-helloworld
- Hibernate-HelloWorld
- Hibernate-helloWorld
- 3.跟我一起学建站之hibernate Helloworld xml版
- Hibernate深入理解----02HelloWorld详解(Hibernate.cfg.xml配置文件详解,创建持久化对象详解)
- Hibernate HelloWorld-13 hibernate 二级缓存
- 2.1 Hibernate的HelloWorld
- hibernate的helloworld
- Hibernate's HelloWorld
- Hibernate HelloWorld(第一步)
- Hibernate的HelloWorld
- Hibernate HelloWorld(一)
- HelloWorld之Hibernate注解
- 【Hibernate】helloworld项目建立
- Socket编程基础(一)
- struts2必备jar包(2.1.6版本)
- 如何进行ibatis动态多条件组合查询以及模糊查询
- pyodbc下连接mssql的便用示例
- ubuntu 12.04下gedit查看txt中文乱码解决办法
- hibernate helloworld(xml)
- hibernate hellowold(annotation)
- Fedora16安装mplayer
- hbm2ddl.auto
- hibernate日志管理
- Hibernate基础配置
- ID生成策略
- Java字节码指令集简介
- Delphi字符串操作的常用函数四