column="MESSAGE_ID"
( w1 [) Y7 z: {7 t# S" e# {! _ >7 [& {8 V. i P
name="text"
: o/ m" n' f( E0 d, U- b5 U; i6 w4 P type="string">; ], {; }9 I" W
name="TEXT"
$ p7 s2 ]/ V$ B& A1 v) A length="100"
9 z* \- I: t# U0 W not-null="true"% t7 n. m% y- B, j L; P6 V' t
/>$ M& R# E u$ G/ ?* X/ `/ W; K
name="nextMessage"; S) L( l ^* ^& D
cascade="all"
" W, {7 a2 T" G* I" g% ?. | column="NEXT_MESSAGE_ID": T5 {: {7 S; y* y2 Z [
/>0 [( e2 [$ h* h# g, G2 Q) v
然后就是测试类 o2 `- h( S8 m
代码:; K: `+ X; U$ D c
package hello;
4 h! f$ s- x9 ], x7 a. n import net.sf.hibernate.cfg.Configuration;' y& a* X6 |6 u3 [5 `, Y
import net.sf.hibernate.SessionFactory; ~$ x+ p: k- i+ r9 b+ {% l! m
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;# ]9 Q: K% M/ e9 f
import net.sf.hibernate.Session;4 w6 o8 B, B# k9 v( W5 I! |+ j
import net.sf.hibernate.Query;! p7 s [+ ~' |- C2 ^% p
import net.sf.hibernate.Hibernate;
& h2 d E0 w, N) z6 j* ^ import net.sf.hibernate.type.LongType;% ^3 r! O2 U1 G* k5 D" ]0 K' Z
import net.sf.hibernate.Transaction; x2 F; D* }! K/ u: {( ?/ A
/**
) r/ V; `6 R1 E" I1 h6 u * @author getdown+ j9 X, u6 \ W1 t- ?9 @+ @
* @version 1.0
; x2 \$ ~# K, x1 @/ S) D! t */% g \0 Y- i3 y* e! ^! p, H
public class Hello {
. A. y/ D' e7 h) b public Hello() {1 i5 Z1 _* h. M+ h
}9 b1 B1 R7 P5 Y& w/ K
public static void main(String[] args) throws Exception {
" `* {6 A$ D. J9 t$ q Configuration cfg = new Configuration().addClass(Message.class);
! A- p6 A8 ~* m1 ]# Z* |" [ /** 顾名思义 构建表。。。第一次运行的时候运行下面语句可以在数据库生成表; Q2 Y' D- `" i4 @3 C/ D7 ~
* 之后可以把下面这句去掉5 ~, a- i6 z: {1 n
* */
; i/ t2 H& L# A" n: a" o+ c% z" U // new SchemaExport(cfg).create(true, true);
% M- {; [. W: }6 t5 v1 J9 S( R. p5 [: o' P //先生成sessionFactory
7 F2 A! [( s; H) v5 a* G0 O SessionFactory sessions = cfg.buildSessionFactory();# C1 E5 ]9 {9 d' G, B5 i: ?
//再从sessionFactory得到一个session D) _3 O: }9 ^: d+ Y g
Session session = sessions.openSession();
9 `& x$ v0 p& _) ` //开始对数据库的操作# @1 F* `" y% c( n+ y6 @
/*----对数据库的创建操作--------*/
# v1 L" F% o; c% |5 [+ n t Message message = new Message("helloWorld");
* a8 H# _9 P5 L2 {; `# `1 E a& I //创建一条记录
+ p/ Q: V& [+ z session.save(message); |