Hibernate 最简单例子

Hibernate 最简单例子

guoqiang-vip@hotmail.com

开发环境

Windows XP Pack 2

MyEclipse 5.5.1 GA

jdk1.5.0_07

Tomcat 5.0

MySQL Server 5.0

MySQL Tools for 5.0

 

开发代码

1 创建数据库,sql语句如下:

DROP TABLE IF EXISTS `test`.`user`;

CREATE TABLE  `test`.`user` (

  `id` int(10) unsigned NOT NULL auto_increment,

  `username` varchar(64) NOT NULL,

  `password` varchar(64) NOT NULL,

  `first_name` varchar(128) NOT NULL,

  `last_name` varchar(128) NOT NULL,

  `date_created` bigint(20) unsigned NOT NULL,

  PRIMARY KEY  (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

2 程序代码:

1hibernate.cfg.xml

package com.guoqiang.hibernate;

 

import org.hibernate.HibernateException;

import org.hibernate.Session;

import org.hibernate.cfg.Configuration;

 

/**

 *ConfiguresandprovidesaccesstoHibernatesessions,tiedtothe

 *currentthreadofexecution.  FollowstheThreadLocalSession

 *pattern,see{@link }.

 */

publicclass HibernateSessionFactory {

 

    /**

     *Locationofhibernate.cfg.xmlfile.

     *LocationshouldbeontheclasspathasHibernateuses 

     *#resourceAsStreamstylelookupforitsconfigurationfile.

     *Thedefaultclasspathlocationofthehibernateconfigfileis

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzjzyw.html