只要在你的工程里导入你需要的包!hibernate\lib下面的几个jar,除了这些还有就是外面的哪个 hibernate.jar别忘了!
解决方案 »
- eWebSoft在线文本编辑器获取数据库内容的问题!小弟高分在线急求!先行谢过了!
- 关于java jdbc连接池的问题在线等!!!!!!!!!
- 求牛人帮忙解决hibernate级联问题
- 关于applet与servlet通信时servlet返回给applet的数据格式问题(高分回报,在线等待)
- 新建JSP群(15005766)诚邀各位加入~~~~~~~~~~
- web 应用关于jstl的问题!
- wml提交到servlet的问题
- 关于单选按钮选定的问题
- 求助 在jspsmartupload中的上传文件的中文名字问题
- 中文问题response.sendRedirect("err.jsp?msg=乱码")??
- 如何实现随机选取数据库记录
- SOS,关于采用sql server2000增加数据库内容
一般一个hibernate的demo包括如下内容;
首先,你的表结构,你的表的怎么设计,比如Customer,里面有多少字段
/*
* Created Thu Dec 23 16:31:55 CST 2004 by MyEclipse Hibernate Tool.
*/import java.io.Serializable;/**
* A class that represents a row in the 'customer' table.
* This class may be customized as it is never re-generated
* after being created.
*/
public class Customer
extends AbstractCustomer
implements Serializable
{
/**
* Simple constructor of Customer instances.
*/
public Customer()
{
} /**
* Constructor of Customer instances given a simple primary key.
* @param cid
*/
public Customer(java.lang.Integer cid)
{
super(cid);
} /* Add customized code below */}那么你要建立相应的PO,说白了就是一个class注意你定义的属性要和你的表匹配.
还有就是需要一个Customer.hbm.xml用来说明你的表和类之间的结构关系,比如:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" ><!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Thu Dec 23 16:31:54 CST 2004 -->
<hibernate-mapping>
<class name="Customer" table="customer">
<id name="cid" column="CID" type="java.lang.Integer">
<generator class="increment"/>
</id>
<property name="username" column="USERNAME" type="java.lang.String" not-null="true" />
<property name="password" column="PASSWORD" type="java.lang.String" />
</class>
</hibernate-mapping>
最后一个hibernate.cfg.xml:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"><!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<hibernate-configuration> <session-factory>
<!-- properties -->
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://localhost/test</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property> <!-- mapping files -->
<mapping resource="Customer.hbm.xml"/>
<mapping resource="Cat.hbm.xml"/>
<mapping resource="Item.hbm.xml"/> </session-factory></hibernate-configuration>