<h1 style="text-align:center"><strong>Hibernate框架</strong></h1>
<h1 align="left">1 hibernate是什么?</h1>
<p> hibernate是一个框架。</p>
<p> hibernate是一个持久化框架。</p>
<p> hibernate是一个封装了JDBC的持久化框架。</p>
<p> 以后使用hibernate不用写jdbc了,select ,insert , delete , update</p>
<p> <span style="color:red">Hibernate</span><span style="color:red">是一个基于</span><span style="color:red">ORM</span><span style="color:red">的封装</span><span style="color:red">JDBC</span><span style="color:red">的持久化框架。</span></p>
<h1>2 持久化?</h1>
<p> 化--过程。</p>
<p> 程序中的数据是临时。</p>
<p> 将程序中临时性的数据持久的保存起来的过程。叫持久化。</p>
<p> 1数据库---jdbc </p>
<p> 2文件操作---io</p>
<h1>3 ORM?</h1>
<p> 对象关系<span style="color:red">映射</span>。</p>
<p> 对象:java程序中类</p>
<p> 关系:关系型数据库中的表</p>
<p>O;</p>
<table border="1" cellpadding="0" cellspacing="0"><tbody><tr><td> <p><span style="color:#7F0055">public</span> <span style="color:#7F0055">class</span> Goods <span style="color:#7F0055">implements</span> java.io.Serializable {<!-- --></p> <p> <span style="color:#3F7F5F">// Fields</span></p> <p> <span style="color:#7F0055">private</span> Integer goodsId;</p> <p> <span style="color:#7F0055">private</span> String <span style="color:#0000C0"> goodsName</span>;</p> <p> <span style="color:#7F0055">private</span> Double <span style="color:#0000C0"> goodsPrice</span>;</p> <p> <span style="color:#7F0055">private</span> Integer <span style="color:#0000C0"> goodsNum</span>;</p> </td></tr></tbody></table>
<p>R:</p>
<table border="1" cellpadding="0" cellspacing="0"><tbody><tr><td> <p>CREATE TABLE goods (</p> <p> goods_id int(11) NOT NULL auto_increment,</p> <p> goods_name varchar(200) default NULL,</p> <p> goods_price double default NULL,</p> <p> goods_num int(11) default NULL,</p> <p> PRIMARY KEY ('goods_id')</p> <p>)</p> </td></tr></tbody></table>
<p>M:Goods.hbm.xml文件,ORM文件</p>
<table border="1" cellpadding="0" cellspacing="0"><tbody><tr><td> <p><span style="color:teal"><</span>hibernate-mapping<span style="color:teal">></span></p> <p> <span style="color:teal"><</span>class <span style="color:#7F007F">name</span>=<span style="color:#2A00FF">"com.no8.domain.Goods"</span> <span style="color:#7F007F">table</span>=<span style="color:#2A00FF">"goods"</span> <span style="color:#7F007F">catalog</span>=<span style="color:#2A00FF">"hibernate"</span><span style="color:teal">></span></p> <p> <span style="color:teal"><</span>id <span style="color:#7F007F">name</span>=<span style="color:#2A00FF">"goodsId"</span> <span style="color:#7F007F">type</span>=<span style="color:#2A00FF">"java.lang.Integer"</span><span style="color:teal">></span></p> <p> <span style="color:teal"><</span>column <span style="color:#7F007F"> name</span>=<span style="color:#2A00FF">"goods_id"</span> <span style="color:teal"> /></span></p> <p> <span style="color:teal"><</span>generator <span style="color:#7F007F"> class</span>=<span style="color:#2A00FF">"identity"</span><span style="color:teal">></</span>generator<span style="color:teal">></span></p> <p> <span style="color:teal"></</span>id<span style="color:teal">></span></p> <p> <span style="color:teal"><</span>property <span style="color:#7F007F"> name</span>=<span style="color:#2A00FF">"goodsName"</span> <span style="color:#7F007F"> type</span>=<span style="color:#2A00FF">"java.lang.String"</span><span style="color:teal">></span></p> <p> <span style="color:teal"><</span>column <span style="color:#7F007F"> name</span>=<span style="color:#2A00FF">"goods_name"</span> <span style="color:#7F007F"> length</span>=<span style="color:#2A00FF">"200"</span> <span style="color:teal">/></span></p> <p> <span style="color:teal"></</span>property<span style="color:teal">></span></p> <p> <span style="color:teal"><</span>property <span style="color:#7F007F"> name</span>=<span style="color:#2A00FF">"goodsPrice"</span> <span style="color:#7F007F"> type</span>=<span style="color:#2A00FF">"java.lang.Double"</span><span style="color:teal">></span></p> <p> <span style="color:teal"><</span>column <span style="color:#7F007F"> name</span>=<span style="color:#2A00FF">"goods_price"</span> <span style="color:#7F007F"> precision</span>=<span style="color:#2A00FF">"22"</span> <span style="color:#7F007F"> scale</span>=<span style="color:#2A00FF">"0"</span> <span style="color:teal">/></span></p> <p> <span style="color:teal"></</span>property<span style="color:teal">></span></p> <p> <span style="color:teal"><</span>property <span style="color:#7F007F"> name</span>=<span style="color:#2A00FF">"goodsNum"</span> <span style="color:#7F007F"> type</span>=<span style="color:#2A00FF">"java.lang.Integer"</span><span style="color:teal">></span></p> <p> <span style="color:teal"><</span>column <span style="color:#7F0 |
|