我的第一个hibernate程序
来源:互联网 发布:ie8 json未定义 编辑:程序博客网 时间:2024/04/27 16:56
Student.java
Student.hbm.xml
hibernate.cfg.xml
- package com.hugui.hibernate.model;
- public class Student {
- private int id;
- private String name;
- private int age;
- 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 int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- }
Student.hbm.xml
- <?xml version="1.0"?>
- <!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
- <!-- 利用hibernate将我们的class和数据库里面的表对应起来了 -->
- <hibernate-mapping package="com.hugui.hibernate.model">
- <!--这个标识Student类对应数据库的student表 ,如果表的名字和类名一样,就只写name就可以了 -->
- <class name="Student" table="student">
- <!--id标签可以理解为主键, name可以理解为调用类里面的getId(),cloumn代表数据库里面的字段名,如果相同,同样可以只写name -->
- <id name="id" column="id"></id>
- <!-- property标签可以理解为普通属性,name可以理解为类里面的getName(),cloumn则是对应数据库里面的字段名,同样,如果name和cloumn相同则可以只写name -->
- <property name="name" column="name"></property>
- <property name="age"></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">
- <hibernate-configuration>
- <session-factory>
- <!-- Database connection settings -->
- <property name="connection.driver_class">
- com.mysql.jdbc.Driver
- </property>
- <property name="connection.url">
- jdbc:mysql://localhost/hibernate
- </property>
- <property name="connection.username">root</property>
- <property name="connection.password">root</property>
- <!-- JDBC connection pool (use the built-in) -->
- <!-- 一般不用这个hibernate自带的连接池,用的最多的是application本身用JNDI注册在里面的连接池-->
- <!-- <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.NoCacheProvider
- </property>
- <!-- Echo all executed SQL to stdout -->
- <!-- 把那个生成的sql打印出来 -->
- <property name="show_sql">true</property>
- <!-- Drop and re-create the database schema on startup -->
- <!-- <property name="hbm2ddl.auto">update</property> -->
- <!-- 告诉hibernate去哪里找那个配置文件 -->
- <mapping resource="com/hugui/hibernate/model/Student.hbm.xml" />
- </session-factory>
- </hibernate-configuration>
- 我的第一个hibernate程序
- 我的第一个hibernate程序
- 我的第一个hibernate程序
- Hibernate+IDEA 2017:记录我的第一个hibernate程序
- Hibernate的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- 我的第一个程序
- DBNull 类
- 配置第一个Hibernate程序
- VC# 2008 ASP.NET Gridview1获取任意行列的值
- How Tomcat Works学习笔记<五>
- hdu 3478 //判联通+二分图判定
- 我的第一个hibernate程序
- 在VC6 IDE中实现通配符查找代码
- http chunked传输
- 老子的软件之道 - 道篇 13 探路者
- Ubuntu 10.10(64位)编译Android 2.3
- Lea 指令
- 杭电 hdu 1856 More is better (并查集)
- 当今粤语懒音现象大观
- 在Windows中编译Nginx源码