hibernate.cfg.xml的基本配置
<!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="hibernate.connection.url">jdbc:mysql://localhost/hibernate_basemapping</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="com/hibernate/pojo/Article.hbm.xml"/>
<mapping
</session-factory>
</hibernate-configuration>
=======================================
<?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.hibernate.pojo">
<class name="Article" table="article">
<id name="id">
<generator class="native"/>
</id>
<property name="title" />
<property name="keywords" />
<property name="content" />
<property name="description" />
</class>
</hibernate-mapping>
=======================================
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static SessionFactory sessionFactory = null;
private static Session session = null;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
} catch (Throwable e) {
throw new ExceptionInInitializerError(e);
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
public static Session getSession(){
return session;
}
public static void closeSession(Session session){
if(null != session){
if (session.isOpen()) {
session.close();
}
}
}
}
=========================
private Class<T> clazz;
public BaseDaoImpl(Class<T> clazz){
this.clazz = clazz;
}
public ArticleDaoImpl(){
super(Article.class);
}
delete(int id){
Object o = getSession().get(clazz,id);
if(o!=null){
getSession().delete(o);
}
}
find(){
getSession().createQuery("from" + clazz.getName));
find(int first,int max)
getSession().createQuery("FROM " + clazz.getName))
.setFirstResult(first)
.setMaxResult(max)
.list();
分享到:
相关推荐
hibernate.cfg.xml hibernate框架的配置文件
Hibernate配置文件hibernate.cfg.xml中配置信息详解!
高级Hibernate4开发技术:ORM思想,hibernate介绍,hibernate.cfg.xml配置,hbm.xml映射文件详解,主键生成策略使用,PO对象状态及状态的转换分析、一级缓存,Hibernate数据检索技术,Hibernate高级映射技术,...
由于spring对hibernate配置文件hibernate.cfg.xml的集成相当好,可以在项目中放弃hibernate.cfg.xml文件,介绍mappingLocations、mappingDirectoryLocations与mappingJarLocations的用法和区别
高级Hibernate4开发技术:ORM思想,hibernate介绍,hibernate.cfg.xml配置,hbm.xml映射文件详解,主键生成策略使用,PO对象状态及状态的转换分析、一级缓存,Hibernate数据检索技术,Hibernate高级映射技术,...
这是Hibernate的配置文件,hibernate.cfg.xml的具体写法,共友友们参考~~谢谢~
hibernate配置文件hibernate.cfg.xml的详细解释
Hibernate.cfg.xml配置总结
hibernate.cfg.xml文件详细解释收集的一个比较好的hibernate.cfg.xml文件解释
(hibernate调用C3p0)hibernate.cfg.xml
JavaEE spring和Hibernate整合(有hibernate.cfg.xml)
hibernate.cfg.xml中各节点的所有属性值,取自hibernate官网,纯天然无污染。原装!
JavaEE spring和Hibernate整合(没有hibernate.cfg.xml)