Person.java
package com; import java.util.Date; public class Person { private String id; private String name; private Date birthday; public Person(){} public Person(String id,String name, Date birthday) { this.id=id; this.name = name; this.birthday = birthday; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } }
Person.hbm.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com"> <class name="Person" table="PERSON"> <id name="id" column="ID"> <generator class="assigned"/> </id> <property name="name" column="NAME"/> <property name="birthday" column="BIRTHDAY"/> </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> <property name="connection.driver_class">oracle.jdbc.OracleDriver</property> <property name="connection.url">数据库URL</property> <property name="connection.username">数据库用户名</property> <property name="connection.password">密码</property> <property name="connection.pool_size">1</property> <property name="dialect">org.hibernate.dialect.OracleDialect</property> <property name="current_session_context_class">thread</property> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="show_sql">true</property> <mapping resource="com/Person.hbm.xml"/> </session-factory> </hibernate-configuration>
测试Main.java
package com; import java.util.Date; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class Main { private static SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory(); private static Session session=sessionFactory.getCurrentSession(); public static void main(String[] args) { // get a person // System.out.println(getPerson("xiao_id")); // add a person // addPerson("xiao_id","xiao_name",new Date()); // update a person // updatePerson("xiao_id","xiao_name_01",new Date()); // delete a person // deletePerson("xiao_id"); } // get a person public static Person getPerson(String id){ session.beginTransaction(); Person person = (Person) session.get(Person.class, id); session.getTransaction().commit(); return person; } // add a person public static void addPerson(String id,String name,Date birthday){ Person person = new Person(id,name,birthday); session.beginTransaction(); session.save(person); session.getTransaction().commit(); } // update a person public static void updatePerson(String id,String name,Date birthday){ Person person = new Person(id,name,birthday); session.beginTransaction(); session.update(person); session.getTransaction().commit(); } // delete a person public static void deletePerson(String id){ session.beginTransaction(); Person person = new Person(); person.setId(id); session.delete(person); session.getTransaction().commit(); } }
相关推荐
Hibernate构建一个CURD的程序
本项目是基于SSH(srpingMVC+spring3=hibernate4)自己学习完成的业余小的增删改查系统,方便大家学习,多多交流。
一个完整struts2+hibernate整合 练习之CURD 完整版,带说明名书,需求分析,适合初学者的练习
Tapestry5.1+Spring2.5.6+Hibernate3.2.5写得简单CURD的程序,借鉴了SpringSide3.1.4.2的配置及数据层。实现了添加,列表,修改,删除,显示等操作。内有源码及生成的WAR文件。可以直接使用!
CURD例子对应的Jar包, 这是第一部分,还有第二部分,这个Jar可以直接使用,我没有整理,但是没有冲突!
Struts2+Hibernate+Spring整合与增、删、改、查CURD操作源码
使用mysql+maven+Hibernate做的一个一对一,一对多小案例,有需要的拿走,这个比较基础
vue简单curd例子。
SpringMVC+Spring3+Hibernate4开发环境搭建
spring3+hibernate4+maven+logback的springMVC架构,有数据表,有jar包,有curd的例子
S2SH+extjs做的简单CURD功能小例子 初学EXTJS一周做的,网上看到N多例子没有源码或是有错误 这个刚写好 数据库用sqlserver2005 例子比较完整 就是没有放jar包(只有jdbc驱动jar和json的jar) 可以自己搭个S2SH环境把...
spring与hibernate整合实现CURD
详细讲解了hibernate 的多对一xml配置以及curd操作,讲解了级联操作,适合初学者学习
thinkPHP之CURD开发简单源码,适合新手学习
NULL 博文链接:https://keshion.iteye.com/blog/1560102
NULL 博文链接:https://tianjun309.iteye.com/blog/695332
struts2与hibernate的整合实现数据的crud操作,还有复选框删除的实例,运用了Jquery的技术。 里面有使用需知,欢迎大家下载。
angularjs CURD Example 单页应用程序
最近单位要用SpringMVC 所以自己学了下 做了个小项目 Jar包都是官方最稳定版本的 ...Spring-3.2.5 + Hibernate-4.2.7 CURD都有Demo 包括文件上传 基本上改改就能用 :) 有Bug 可以M我 zzlovesy@hotmail.com