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

📄 session_api.pot

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 POT
📖 第 1 页 / 共 4 页
字号:
#, no-c-formatmsgid "Queries that return tuples"msgstr ""#. Tag: para#: session_api.xml:298#, no-c-formatmsgid "Hibernate queries sometimes return tuples of objects, in which case each tuple is returned as an array:"msgstr ""#. Tag: programlisting#: session_api.xml:303#, no-c-formatmsgid ""      "<![CDATA[Iterator kittensAndMothers = sess.createQuery(\n"      "            \"select kitten, mother from Cat kitten join kitten.mother mother\")\n"      "            .list()\n"      "            .iterator();\n"      "\n"      "while ( kittensAndMothers.hasNext() ) {\n"      "    Object[] tuple = (Object[]) kittensAndMothers.next();\n"      "    Cat kitten = (Cat) tuple[0];\n"      "    Cat mother = (Cat) tuple[1];\n"      "    ....\n"      "}]]>"msgstr ""#. Tag: title#: session_api.xml:308#, no-c-formatmsgid "Scalar results"msgstr ""#. Tag: para#: session_api.xml:310#, no-c-formatmsgid "Queries may specify a property of a class in the <literal>select</literal> clause. They may even call SQL aggregate functions. Properties or aggregates are considered \"scalar\" results (and not entities in persistent state)."msgstr ""#. Tag: programlisting#: session_api.xml:316#, no-c-formatmsgid ""      "<![CDATA[Iterator results = sess.createQuery(\n"      "        \"select cat.color, min(cat.birthdate), count(cat) from Cat cat \" +\n"      "        \"group by cat.color\")\n"      "        .list()\n"      "        .iterator();\n"      "\n"      "while ( results.hasNext() ) {\n"      "    Object[] row = (Object[]) results.next();\n"      "    Color type = (Color) row[0];\n"      "    Date oldest = (Date) row[1];\n"      "    Integer count = (Integer) row[2];\n"      "    .....\n"      "}]]>"msgstr ""#. Tag: title#: session_api.xml:321#, no-c-formatmsgid "Bind parameters"msgstr ""#. Tag: para#: session_api.xml:323#, no-c-formatmsgid "Methods on <literal>Query</literal> are provided for binding values to named parameters or JDBC-style <literal>?</literal> parameters. <emphasis>Contrary to JDBC, Hibernate numbers parameters from zero.</emphasis> Named parameters are identifiers of the form <literal>:name</literal> in the query string. The advantages of named parameters are:"msgstr ""#. Tag: para#: session_api.xml:333#, no-c-formatmsgid "named parameters are insensitive to the order they occur in the query string"msgstr ""#. Tag: para#: session_api.xml:339#, no-c-formatmsgid "they may occur multiple times in the same query"msgstr ""#. Tag: para#: session_api.xml:344#, no-c-formatmsgid "they are self-documenting"msgstr ""#. Tag: programlisting#: session_api.xml:350#, no-c-formatmsgid ""      "<![CDATA[//named parameter (preferred)\n"      "Query q = sess.createQuery(\"from DomesticCat cat where cat.name = :name\");\n"      "q.setString(\"name\", \"Fritz\");\n"      "Iterator cats = q.iterate();]]>"msgstr ""#. Tag: programlisting#: session_api.xml:352#, no-c-formatmsgid ""      "<![CDATA[//positional parameter\n"      "Query q = sess.createQuery(\"from DomesticCat cat where cat.name = ?\");\n"      "q.setString(0, \"Izi\");\n"      "Iterator cats = q.iterate();]]>"msgstr ""#. Tag: programlisting#: session_api.xml:354#, no-c-formatmsgid ""      "<![CDATA[//named parameter list\n"      "List names = new ArrayList();\n"      "names.add(\"Izi\");\n"      "names.add(\"Fritz\");\n"      "Query q = sess.createQuery(\"from DomesticCat cat where cat.name in (:namesList)\");\n"      "q.setParameterList(\"namesList\", names);\n"      "List cats = q.list();]]>"msgstr ""#. Tag: title#: session_api.xml:359#, no-c-formatmsgid "Pagination"msgstr ""#. Tag: para#: session_api.xml:361#, no-c-formatmsgid "If you need to specify bounds upon your result set (the maximum number of rows you want to retrieve and / or the first row you want to retrieve) you should use methods of the <literal>Query</literal> interface:"msgstr ""#. Tag: programlisting#: session_api.xml:367#, no-c-formatmsgid ""      "<![CDATA[Query q = sess.createQuery(\"from DomesticCat cat\");\n"      "q.setFirstResult(20);\n"      "q.setMaxResults(10);\n"      "List cats = q.list();]]>"msgstr ""#. Tag: para#: session_api.xml:369#, no-c-formatmsgid "Hibernate knows how to translate this limit query into the native SQL of your DBMS."msgstr ""#. Tag: title#: session_api.xml:377#, no-c-formatmsgid "Scrollable iteration"msgstr ""#. Tag: para#: session_api.xml:379#, no-c-formatmsgid "If your JDBC driver supports scrollable <literal>ResultSet</literal>s, the <literal>Query</literal> interface may be used to obtain a <literal>ScrollableResults</literal> object, which allows flexible navigation of the query results."msgstr ""#. Tag: programlisting#: session_api.xml:386#, no-c-formatmsgid ""      "<![CDATA[Query q = sess.createQuery(\"select cat.name, cat from DomesticCat cat \" +\n"      "                            \"order by cat.name\");\n"      "ScrollableResults cats = q.scroll();\n"      "if ( cats.first() ) {\n"      "\n"      "    // find the first name on each page of an alphabetical list of cats by name\n"      "    firstNamesOfPages = new ArrayList();\n"      "    do {\n"      "        String name = cats.getString(0);\n"      "        firstNamesOfPages.add(name);\n"      "    }\n"      "    while ( cats.scroll(PAGE_SIZE) );\n"      "\n"      "    // Now get the first page of cats\n"      "    pageOfCats = new ArrayList();\n"      "    cats.beforeFirst();\n"      "    int i=0;\n"      "    while( ( PAGE_SIZE > i++ ) && cats.next() ) pageOfCats.add( cats.get(1) );\n"      "\n"      "}\n"      "cats.close()]]>"msgstr ""#. Tag: para#: session_api.xml:388#, no-c-formatmsgid "Note that an open database connection (and cursor) is required for this functionality, use <literal>setMaxResult()</literal>/<literal>setFirstResult()</literal> if you need offline pagination functionality."msgstr ""#. Tag: title#: session_api.xml:397#, no-c-formatmsgid "Externalizing named queries"msgstr ""#. Tag: para#: session_api.xml:399#, no-c-formatmsgid "You may also define named queries in the mapping document. (Remember to use a <literal>CDATA</literal> section if your query contains characters that could be interpreted as markup.)"msgstr ""#. Tag: programlisting#: session_api.xml:405#, no-c-formatmsgid ""      "<![CDATA[<query name=\"ByNameAndMaximumWeight\"><![CDATA[\n"      "    from eg.DomesticCat as cat\n"      "        where cat.name = ?\n"      "        and cat.weight > ?\n"      "] ]></query>]]>"msgstr ""#. Tag: para#: session_api.xml:407#, no-c-formatmsgid "Parameter binding and executing is done programatically:"msgstr ""#. Tag: programlisting#: session_api.xml:411#, no-c-formatmsgid ""      "<![CDATA[Query q = sess.getNamedQuery(\"ByNameAndMaximumWeight\");\n"      "q.setString(0, name);\n"      "q.setInt(1, minWeight);\n"      "List cats = q.list();]]>"msgstr ""#. Tag: para#: session_api.xml:413#, no-c-formatmsgid "Note that the actual program code is independent of the query language that is used, you may also define native SQL queries in metadata, or migrate existing queries to Hibernate by placing them in mapping files."msgstr ""#. Tag: para#: session_api.xml:419#, no-c-formatmsgid "Also note that a query declaration inside a <literal>&lt;hibernate-mapping&gt;</literal> element requires a global unique name for the query, while a query declaration inside a <literal>&lt;class&gt;</literal> element is made unique automatically by prepending the fully qualified name of the class, for example <literal>eg.Cat.ByNameAndMaximumWeight</literal>."msgstr ""#. Tag: title#: session_api.xml:432#, no-c-formatmsgid "Filtering collections"msgstr ""#. Tag: para#: session_api.xml:433#, no-c-formatmsgid "A collection <emphasis>filter</emphasis> is a special type of query that may be applied to a persistent collection or array. The query string may refer to <literal>this</literal>, meaning the current collection element."msgstr ""#. Tag: programlisting#: session_api.xml:439#, no-c-formatmsgid ""      "<![CDATA[Collection blackKittens = session.createFilter(\n"      "    pk.getKittens(), \n"      "    \"where this.color = ?\")\n"      "    .setParameter( Color.BLACK, Hibernate.custom(ColorUserType.class) )\n"      "    .list()\n"      ");]]>"msgstr ""#. Tag: para#: session_api.xml:441#, no-c-formatmsgid "The returned collection is considered a bag, and it's a copy of the given collection. The original collection is not modified (this is contrary to the implication of the name \"filter\", but consistent with expected behavior)."msgstr ""#. Tag: para#: session_api.xml:447#, no-c-formatmsgid "Observe that filters do not require a <literal>from</literal> clause (though they may have one if required). Filters are not limited to returning the collection elements themselves."msgstr ""#. Tag: programlisting#: session_api.xml:452#, no-c-formatmsgid ""      "<![CDATA[Collection blackKittenMates = session.createFilter(\n"      "    pk.getKittens(), \n"      "    \"select this.mate where this.color = eg.Color.BLACK.intValue\")\n"      "    .list();]]>"msgstr ""#. Tag: para#: session_api.xml:454#, no-c-formatmsgid "Even an empty filter query is useful, e.g. to load a subset of elements in a huge collection:"msgstr ""#. Tag: programlisting#: session_api.xml:459#, no-c-formatmsgid ""      "<![CDATA[Collection tenKittens = session.createFilter(\n"      "    mother.getKittens(), \"\")\n"      "    .setFirstResult(0).setMaxResults(10)\n"      "    .list();]]>"msgstr ""#. Tag: title#: session_api.xml:464#, no-c-formatmsgid "Criteria queries"msgstr ""#. Tag: para#: session_api.xml:466#, no-c-formatmsgid "HQL is extremely powerful but some developers prefer to build queries dynamically, using an object-oriented API, rather than building query strings. Hibernate provides an intuitive <literal>Criteria</literal> query API for these cases:"msgstr ""#. Tag: programlisting#: session_api.xml:472#, no-c-formatmsgid ""      "<![CDATA[Criteria crit = session.createCriteria(Cat.class);\n"      "crit.add( Restrictions.eq( \"color\", eg.Color.BLACK ) );\n"      "crit.setMaxResults(10);\n"      "List cats = crit.list();]]>"msgstr ""#. Tag: para#: session_api.xml:474#, no-c-formatmsgid "The <literal>Criteria</literal> and the associated <literal>Example</literal> API are discussed in more detail in <xref linkend=\"querycriteria\"/>."msgstr ""#. Tag: title#: session_api.xml:482#, no-c-formatmsgid "Queries in native SQL"

⌨️ 快捷键说明

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