hibernate 初学
来源:互联网 发布:片仔癀淘宝旗舰店 编辑:程序博客网 时间:2024/06/05 11:44
hibernate版本:3.3.2
文件目录:
*.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-mapping>
<class name="com.zzl.Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="native"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</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">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@ip:unieap</property>
<property name="connection.username">tabuser</property>
<property name="connection.password">tabuser</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</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 -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<!--
<property name="hbm2ddl.auto">create</property>
-->
<mapping resource="com/zzl/Event.hbm.xml"/>
</session-factory>
</hibernate-configuration>
查找方言超链接:http://kb.cnblogs.com/a/1587624/
实体类:
package com.zzl;
import java.util.Date;
public class Event
{
private Long id;
private String title;
private Date date;
public Event(){}
public Long getId()
{
return id;
}
private void setId(Long id)
{
this.id = id;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public Date getDate()
{
return date;
}
public void setDate(Date date)
{
this.date = date;
}
}
辅助类:
package com.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil
{
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
主类:
package com.app;
import java.util.Date;
import org.hibernate.Session;
import com.util.HibernateUtil;
import com.zzl.Event;
public class App
{
public static void main(String[] args)
{
Session session=HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event event=new Event();
event.setTitle("zzl");
event.setDate(new Date());
session.save(event);
session.getTransaction().commit();
HibernateUtil.getSessionFactory().close();
}
}
- Hibernate初学
- Hibernate初学
- hibernate 初学
- Hibernate 初学
- 初学Hibernate
- 初学hibernate
- hibernate初学
- 【Hibernate】初学Hibernate(一)
- Hibernate初学有感
- Hibernate dao初学体会
- 初学Hibernate问题
- 初学hibernate错误
- 初学hibernate笔记
- 初学hibernate总结
- 初学hibernate错误请教..
- hibernate框架初学
- 初学Hibernate(2)
- 初学Hibernate(3)
- C++ 编译器的函数名修饰规则
- android设置方向
- Oracle 游标记录使用示例
- PB 并发控制
- POJ 3084 最大流最小割求割边
- hibernate 初学
- 常见Android笔试题
- Virtual Box 虚拟机和主机之间进行通信的设置方法
- Spring inject Date into bean property – CustomDateEditor
- Android上传文件至服务器
- DDK(Driver Developer Kit)和WDK(Windows Driver Kit)的区别
- c库函数参考手册
- POJ 3204 求使得最大流增大的边
- 把一个逗号分开的字符串转化为数组的两个方法