⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tutorial.html

📁 是一个中文的Hibernate库文档
💻 HTML
📖 第 1 页 / 共 5 页
字号:
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;&lt;hibernate-configuration&gt;    &lt;session-factory&gt;        &lt;!-- Database connection settings --&gt;        &lt;property name="connection.driver_class"&gt;org.hsqldb.jdbcDriver&lt;/property&gt;        &lt;property name="connection.url"&gt;jdbc:hsqldb:data/tutorial&lt;/property&gt;        &lt;property name="connection.username"&gt;sa&lt;/property&gt;        &lt;property name="connection.password"&gt;&lt;/property&gt;        &lt;!-- JDBC connection pool (use the built-in) --&gt;        &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;        &lt;!-- SQL dialect --&gt;        &lt;property name="dialect"&gt;org.hibernate.dialect.HSQLDialect&lt;/property&gt;        &lt;!-- Echo all executed SQL to stdout --&gt;        &lt;property name="show_sql"&gt;true&lt;/property&gt;        &lt;!-- Drop and re-create the database schema on startup --&gt;        &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;        &lt;mapping resource="Event.hbm.xml"/&gt;    &lt;/session-factory&gt;&lt;/hibernate-configuration&gt;</pre><p>		&#27880;&#24847;&#36825;&#20010;XML&#37197;&#32622;&#20351;&#29992;&#20102;&#19968;&#20010;&#19981;&#21516;&#30340;DTD&#12290;&#25105;&#20204;&#37197;&#32622;Hibernate&#30340;<tt class="literal">SessionFactory</tt>&#65293;		&#19968;&#20010;&#20851;&#32852;&#20110;&#29305;&#23450;&#25968;&#25454;&#24211;&#20840;&#23616;&#24615;&#30340;&#24037;&#21378;&#65288;factory&#65289;&#12290;&#22914;&#26524;&#20320;&#35201;&#20351;&#29992;&#22810;&#20010;&#25968;&#25454;&#24211;&#65292;&#36890;&#24120;&#24212;&#35813;&#22312;&#22810;&#20010;&#37197;&#32622;&#25991;&#20214;&#20013;&#20351;&#29992;&#22810;&#20010;<tt class="literal">&lt;session-factory&gt;</tt>		&#36827;&#34892;&#37197;&#32622;&#65288;&#22312;&#26356;&#26089;&#30340;&#21551;&#21160;&#27493;&#39588;&#20013;&#36827;&#34892;&#65289;&#12290;            </p><p>		 &#26368;&#24320;&#22987;&#30340;4&#20010;<tt class="literal">property</tt>&#20803;&#32032;&#21253;&#21547;&#24517;&#35201;&#30340;JDBC&#36830;&#25509;&#20449;&#24687;&#12290;dialect<tt class="literal">property</tt>		&#34920;&#26126;Hibernate&#24212;&#35813;&#20135;&#29983;&#38024;&#23545;&#29305;&#23450;&#25968;&#25454;&#24211;&#35821;&#27861;&#30340;SQL&#35821;&#21477;&#12290;<tt class="literal">hbm2ddl.auto</tt>&#36873;&#39033;&#23558;&#33258;&#21160;&#29983;&#25104;&#25968;&#25454;&#24211;&#34920;&#23450;&#20041;&#65288;schema&#65289;&#65293;		&#30452;&#25509;&#25554;&#20837;&#25968;&#25454;&#24211;&#20013;&#12290;&#24403;&#28982;&#36825;&#20010;&#36873;&#39033;&#20063;&#21487;&#20197;&#34987;&#20851;&#38381;&#65288;&#36890;&#36807;&#21435;&#38500;&#36825;&#20010;&#36873;&#39033;&#65289;&#25110;&#32773;&#36890;&#36807;Ant&#20219;&#21153;<tt class="literal">SchemaExport</tt>&#26469;&#25226;&#25968;&#25454;&#24211;&#34920;&#23450;&#20041;&#23548;&#20837;&#19968;&#20010;&#25991;&#20214;&#20013;&#36827;&#34892;&#20248;&#21270;&#12290;		&#26368;&#21518;&#65292;&#20026;&#25345;&#20037;&#21270;&#31867;&#21152;&#20837;&#26144;&#23556;&#25991;&#20214;&#12290;            </p><p>		&#25226;&#36825;&#20010;&#25991;&#20214;&#25335;&#36125;&#21040;&#28304;&#20195;&#30721;&#30446;&#24405;&#19979;&#38754;&#65292;&#36825;&#26679;&#23427;&#23601;&#20301;&#20110;classpath&#30340;root&#36335;&#24452;&#19978;&#12290;Hibernate&#22312;&#21551;&#21160;&#26102;&#20250;&#33258;&#21160;		&#22312;&#23427;&#30340;&#26681;&#30446;&#24405;&#24320;&#22987;&#23547;&#25214;&#21517;&#20026;<tt class="literal">hibernate.cfg.xml</tt>&#30340;&#37197;&#32622;&#25991;&#20214;&#12290;            </p></div><div class="sect2" lang="zh-cn"><div class="titlepage"><div><div><h3 class="title"><a name="tutorial-firstapp-ant"></a>2.2.4.&nbsp;		&#29992;Ant&#32534;&#35793;		</h3></div></div><div></div></div><p>		&#22312;&#36825;&#20010;&#25945;&#31243;&#37324;&#38754;&#65292;&#25105;&#20204;&#23558;&#29992;Ant&#26469;&#32534;&#35793;&#31243;&#24207;&#12290;&#20320;&#24517;&#39035;&#20808;&#23433;&#35013;Ant&#65293;&#21487;&#20197;&#20174;<a href="http://ant.apache.org/bindownload.cgi" target="_top">Ant download page</a>		&#19979;&#36733;&#23427;&#12290;&#24590;&#26679;&#23433;&#35013;Ant&#19981;&#26159;&#36825;&#20010;&#25945;&#31243;&#30340;&#20869;&#23481;&#65292;&#35831;&#21442;&#32771;<a href="http://ant.apache.org/manual/index.html" target="_top">Ant manual</a>&#12290;		&#24403;&#20320;&#23433;&#35013;&#23436;&#20102;Ant&#65292;&#25105;&#20204;&#23601;&#21487;&#20197;&#24320;&#22987;&#21019;&#24314;&#32534;&#35793;&#33050;&#26412;&#65292;&#23427;&#30340;&#25991;&#20214;&#21517;&#26159;<tt class="literal">build.xml</tt>&#65292;&#25226;&#23427;&#30452;&#25509;&#25918;&#22312;&#24320;&#21457;&#30446;&#24405;&#19979;&#38754;&#12290;            </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">			&#23436;&#21892;Ant		</h3><p>			&#27880;&#24847;Ant&#30340;&#20998;&#21457;&#29256;&#36890;&#24120;&#21151;&#33021;&#37117;&#26159;&#19981;&#23436;&#25972;&#30340;&#65288;&#23601;&#20687;Ant FAQ&#37324;&#38754;&#35828;&#24471;&#37027;&#26679;&#65289;&#65292;&#25152;&#20197;&#20320;&#24120;&#24120;&#19981;&#24471;&#19981;&#38656;&#35201;&#33258;&#24049;&#21160;&#25163;&#26469;&#23436;&#21892;Ant&#12290;			&#20363;&#22914;&#65306;&#22914;&#26524;&#20320;&#24076;&#26395;&#22312;&#20320;&#30340;build&#25991;&#20214;&#37324;&#38754;&#20351;&#29992;JUnit&#21151;&#33021;&#12290;&#20026;&#20102;&#35753;JUnit&#20219;&#21153;&#34987;&#28608;&#27963;&#65288;&#36825;&#20010;&#25945;&#31243;&#37324;&#38754;&#25105;&#20204;&#24182;&#19981;&#38656;&#35201;&#36825;&#20010;&#20219;&#21153;&#65289;&#65292;			&#20320;&#24517;&#39035;&#25335;&#36125;junit.jar&#21040;<tt class="literal">ANT_HOME/lib</tt>&#30446;&#24405;&#19979;&#25110;&#32773;&#21024;&#38500;<tt class="literal">ANT_HOME/lib/ant-junit.jar</tt>&#36825;&#20010;&#25554;&#20214;&#12290;                </p></div><p>		&#19968;&#20010;&#22522;&#26412;&#30340;build&#25991;&#20214;&#30475;&#36215;&#26469;&#20687;&#36825;&#26679;            </p><pre class="programlisting">&lt;project name="hibernate-tutorial" default="compile"&gt;    &lt;property name="sourcedir" value="${basedir}/src"/&gt;    &lt;property name="targetdir" value="${basedir}/bin"/&gt;    &lt;property name="librarydir" value="${basedir}/lib"/&gt;    &lt;path id="libraries"&gt;        &lt;fileset dir="${librarydir}"&gt;            &lt;include name="*.jar"/&gt;        &lt;/fileset&gt;    &lt;/path&gt;    &lt;target name="clean"&gt;        &lt;delete dir="${targetdir}"/&gt;        &lt;mkdir dir="${targetdir}"/&gt;    &lt;/target&gt;    &lt;target name="compile" depends="clean, copy-resources"&gt;      &lt;javac srcdir="${sourcedir}"             destdir="${targetdir}"             classpathref="libraries"/&gt;    &lt;/target&gt;    &lt;target name="copy-resources"&gt;        &lt;copy todir="${targetdir}"&gt;            &lt;fileset dir="${sourcedir}"&gt;                &lt;exclude name="**/*.java"/&gt;            &lt;/fileset&gt;        &lt;/copy&gt;    &lt;/target&gt;&lt;/project&gt;</pre><p>		&#36825;&#20010;&#23558;&#21578;&#35785;Ant&#25226;&#25152;&#26377;&#22312;lib&#30446;&#24405;&#19979;&#20197;<tt class="literal">.jar</tt>&#32467;&#23614;&#30340;&#25991;&#20214;&#21152;&#20837;classpath&#20013;&#29992;&#26469;&#36827;&#34892;&#32534;&#35793;&#12290;		&#23427;&#20063;&#23558;&#25226;&#25152;&#26377;&#30340;&#38750;Java&#28304;&#20195;&#30721;&#25991;&#20214;&#65292;&#20363;&#22914;&#37197;&#32622;&#21644;Hibernate&#26144;&#23556;&#25991;&#20214;&#65292;&#25335;&#36125;&#21040;&#30446;&#26631;&#30446;&#24405;&#19979;&#12290;&#22914;&#26524;&#20320;&#29616;&#22312;&#36816;&#34892;Ant&#65292;		&#20320;&#23558;&#24471;&#21040;&#20197;&#19979;&#36755;&#20986;&#65306;            </p><pre class="programlisting">C:\hibernateTutorial\&gt;antBuildfile: build.xmlcopy-resources:     [copy] Copying 2 files to C:\hibernateTutorial\bincompile:    [javac] Compiling 1 source file to C:\hibernateTutorial\binBUILD SUCCESSFULTotal time: 1 second </pre></div><div class="sect2" lang="zh-cn"><div class="titlepage"><div><div><h3 class="title"><a name="tutorial-firstapp-helpers"></a>2.2.5.&nbsp;		&#23433;&#35013;&#21644;&#24110;&#21161;		</h3></div></div><div></div></div><p>		&#26159;&#26102;&#20505;&#26469;&#21152;&#36733;&#21644;&#20648;&#23384;&#19968;&#20123;<tt class="literal">Event</tt>&#23545;&#35937;&#20102;&#65292;&#20294;&#26159;&#39318;&#20808;&#25105;&#20204;&#19981;&#24471;&#19981;&#23436;&#25104;&#19968;&#20123;&#22522;&#30784;&#30340;&#20195;&#30721;&#12290;		&#25105;&#20204;&#24517;&#39035;&#21551;&#21160;Hibernate&#12290;&#36825;&#20010;&#21551;&#21160;&#36807;&#31243;&#21253;&#25324;&#21019;&#24314;&#19968;&#20010;&#20840;&#23616;&#24615;&#30340;<tt class="literal">SessoinFactory</tt>&#24182;&#25226;&#23427;&#20648;&#23384;&#22312;&#19968;&#20010;&#24212;&#29992;&#31243;&#24207;&#23481;&#26131;&#35775;&#38382;&#30340;&#22320;&#26041;&#12290;		<tt class="literal">SessionFactory</tt>&#21487;&#20197;&#21019;&#24314;&#24182;&#25171;&#24320;&#26032;&#30340;<tt class="literal">Session</tt>&#12290;		&#19968;&#20010;<tt class="literal">Session</tt>&#20195;&#34920;&#19968;&#20010;&#21333;&#32447;&#31243;&#30340;&#21333;&#20803;&#25805;&#20316;&#65292;<tt class="literal">SessionFactory</tt>&#21017;&#26159;&#19968;&#20010;&#32447;&#31243;&#23433;&#20840;&#30340;&#20840;&#23616;&#23545;&#35937;&#65292;&#21482;&#38656;&#35201;&#21019;&#24314;&#19968;&#27425;&#12290;            </p><p>		&#25105;&#20204;&#23558;&#21019;&#24314;&#19968;&#20010;<tt class="literal">HibernateUtil</tt>&#24110;&#21161;&#31867;&#65288;helper class&#65289;&#26469;&#36127;&#36131;&#21551;&#21160;Hibernate&#24182;&#20351;		&#25805;&#20316;<tt class="literal">Session</tt>&#21464;&#24471;&#23481;&#26131;&#12290;&#36825;&#20010;&#24110;&#21161;&#31867;&#23558;&#20351;&#29992;&#34987;&#31216;&#20026;<span class="emphasis"><em>ThreadLocal Session</em></span>		&#30340;&#27169;&#24335;&#26469;&#20445;&#35777;&#24403;&#21069;&#30340;&#21333;&#20803;&#25805;&#20316;&#21644;&#24403;&#21069;&#32447;&#31243;&#30456;&#20851;&#32852;&#12290;&#35753;&#25105;&#20204;&#26469;&#30475;&#19968;&#30524;&#23427;&#30340;&#23454;&#29616;&#65306;            </p><pre class="programlisting">import org.hibernate.*;import org.hibernate.cfg.*;public class HibernateUtil {    public static final SessionFactory sessionFactory;    static {        try {            // Create the SessionFactory from hibernate.cfg.xml            sessionFactory = new Configuration().configure().buildSessionFactory();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -