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

📄 batch.pot

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 POT
📖 第 1 页 / 共 2 页
字号:
# SOME DESCRIPTIVE TITLE.# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.##, fuzzymsgid ""msgstr """Project-Id-Version: PACKAGE VERSION\n""Report-Msgid-Bugs-To: http://bugs.kde.org\n""POT-Creation-Date: 2008-08-14 15:28+0000\n""PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n""Last-Translator: FULL NAME <EMAIL@ADDRESS>\n""Language-Team: LANGUAGE <kde-i18n-doc@kde.org>\n""MIME-Version: 1.0\n""Content-Type: application/x-xml2pot; charset=UTF-8\n""Content-Transfer-Encoding: 8bit\n"#. Tag: title#: batch.xml:29#, no-c-formatmsgid "Batch processing"msgstr ""#. Tag: para#: batch.xml:31#, no-c-formatmsgid "A naive approach to inserting 100 000 rows in the database using Hibernate might look like this:"msgstr ""#. Tag: programlisting#: batch.xml:36#, no-c-formatmsgid ""      "<![CDATA[Session session = sessionFactory.openSession();\n"      "Transaction tx = session.beginTransaction();\n"      "for ( int i=0; i<100000; i++ ) {\n"      "    Customer customer = new Customer(.....);\n"      "    session.save(customer);\n"      "}\n"      "tx.commit();\n"      "session.close();]]>"msgstr ""#. Tag: para#: batch.xml:38#, no-c-formatmsgid "This would fall over with an <literal>OutOfMemoryException</literal> somewhere around the 50 000th row. That's because Hibernate caches all the newly inserted <literal>Customer</literal> instances in the session-level cache."msgstr ""#. Tag: para#: batch.xml:44#, no-c-formatmsgid "In this chapter we'll show you how to avoid this problem. First, however, if you are doing batch processing, it is absolutely critical that you enable the use of JDBC batching, if you intend to achieve reasonable performance. Set the JDBC batch size to a reasonable number (say, 10-50):"msgstr ""#. Tag: programlisting#: batch.xml:51#, no-c-formatmsgid "<![CDATA[hibernate.jdbc.batch_size 20]]>"msgstr ""#. Tag: para#: batch.xml:53#, no-c-formatmsgid "Note that Hibernate disables insert batching at the JDBC level transparently if you use an <literal>identiy</literal> identifier generator."msgstr ""#. Tag: para#: batch.xml:58#, no-c-formatmsgid "You also might like to do this kind of work in a process where interaction with the second-level cache is completely disabled:"msgstr ""#. Tag: programlisting#: batch.xml:63#, no-c-formatmsgid "<![CDATA[hibernate.cache.use_second_level_cache false]]>"msgstr ""#. Tag: para#: batch.xml:65#, no-c-formatmsgid "However, this is not absolutely necessary, since we can explicitly set the <literal>CacheMode</literal> to disable interaction with the second-level cache."msgstr ""#. Tag: title#: batch.xml:71#, no-c-formatmsgid "Batch inserts"msgstr ""#. Tag: para#: batch.xml:73#, no-c-formatmsgid "When making new objects persistent, you must <literal>flush()</literal> and then <literal>clear()</literal> the session regularly, to control the size of the first-level cache."msgstr ""#. Tag: programlisting#: batch.xml:79#, no-c-formatmsgid ""      "<![CDATA[Session session = sessionFactory.openSession();\n"      "Transaction tx = session.beginTransaction();\n"      "   \n"      "for ( int i=0; i<100000; i++ ) {\n"      "    Customer customer = new Customer(.....);\n"      "    session.save(customer);\n"      "    if ( i % 20 == 0 ) { //20, same as the JDBC batch size\n"      "        //flush a batch of inserts and release memory:\n"      "        session.flush();\n"      "        session.clear();\n"      "    }\n"      "}\n"      "   \n"      "tx.commit();\n"      "session.close();]]>"msgstr ""#. Tag: title#: batch.xml:84#, no-c-formatmsgid "Batch updates"msgstr ""#. Tag: para#: batch.xml:86#, no-c-formatmsgid "For retrieving and updating data the same ideas apply. In addition, you need to use <literal>scroll()</literal> to take advantage of server-side cursors for queries that return many rows of data."msgstr ""#. Tag: programlisting#: batch.xml:92#, no-c-formatmsgid ""      "<![CDATA[Session session = sessionFactory.openSession();\n"      "Transaction tx = session.beginTransaction();\n"      "   \n"      "ScrollableResults customers = session.getNamedQuery(\"GetCustomers\")\n"      "    .setCacheMode(CacheMode.IGNORE)\n"      "    .scroll(ScrollMode.FORWARD_ONLY);\n"      "int count=0;\n"      "while ( customers.next() ) {\n"      "    Customer customer = (Customer) customers.get(0);\n"      "    customer.updateStuff(...);\n"      "    if ( ++count % 20 == 0 ) {\n"      "        //flush a batch of updates and release memory:\n"      "        session.flush();\n"      "        session.clear();\n"      "    }\n"      "}\n"      "   \n"      "tx.commit();\n"      "session.close();]]>"msgstr ""#. Tag: title#: batch.xml:97#, no-c-formatmsgid "The StatelessSession interface"msgstr ""#. Tag: para#: batch.xml:98#, no-c-formatmsgid "Alternatively, Hibernate provides a command-oriented API that may be used for streaming data to and from the database in the form of detached objects. A <literal>StatelessSession</literal> has no persistence context associated with it and does not provide many of the higher-level life cycle semantics. In particular, a stateless session does not implement a first-level cache nor interact with any second-level or query cache. It does not implement transactional write-behind or automatic dirty checking. Operations performed using a stateless session do not ever cascade to associated instances. Collections are ignored by a stateless session. Operations performed via a stateless session bypass Hibernate's event model and interceptors. Stateless sessions are vulnerable to data aliasing effects, due to the lack of a first-level cache. A stateless session is a lower-level abstraction, much closer to the underlying JDBC."msgstr ""#. Tag: programlisting#: batch.xml:113#, no-c-formatmsgid ""      "<![CDATA[StatelessSession session = sessionFactory.openStatelessSession();\n"      "Transaction tx = session.beginTransaction();\n"      "   \n"      "ScrollableResults customers = session.getNamedQuery(\"GetCustomers\")\n"      "    .scroll(ScrollMode.FORWARD_ONLY);\n"      "while ( customers.next() ) {\n"      "    Customer customer = (Customer) customers.get(0);\n"      "    customer.updateStuff(...);\n"      "    session.update(customer);\n"      "}\n"      "   \n"      "tx.commit();\n"      "session.close();]]>"msgstr ""#. Tag: para#: batch.xml:115

⌨️ 快捷键说明

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