{"id":402,"date":"2014-05-17T23:48:58","date_gmt":"2014-05-17T14:48:58","guid":{"rendered":"http:\/\/www.typea.info\/blog\/index.php\/2014\/05\/17\/java_ee_7_8_jpa_2_criteria_api\/"},"modified":"2014-05-17T23:48:58","modified_gmt":"2014-05-17T14:48:58","slug":"java_ee_7_8_jpa_2_criteria_api","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/17\/java_ee_7_8_jpa_2_criteria_api\/","title":{"rendered":"Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(8) JPA \u554f\u3044\u5408\u308f\u305b(2) \u52d5\u7684\u30af\u30a8\u30ea\u3068Criteria API \u3092\u8a66\u3059"},"content":{"rendered":"<ol>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/04\/28\/java_ee_7_1_wildfly_jboss_tools_ear_arquillian\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(1) WildFly + JBoss Tools \u3067 EAR\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057 Arquillian \u3067 \u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u30b0\u30ea\u30fc\u30f3\u306b\u3059\u308b\u3068\u3053\u308d\u307e\u3067<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/04\/28\/java_ee_7_2_wildfly_datasource\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(2) WildFly \u306b DataSource\u3092\u4f5c\u6210<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/04\/29\/java_ee_7_3_jpamysqlarquillian\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(3) JPA\u304b\u3089MySQL\u306b\u63a5\u7d9a\u3059\u308b\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092Arquillian\u3067\u5b9f\u884c<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/05\/java_ee_4_java_ee_didependency_injection_cdicontexts_and_dependency_injection\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(4) Java EE \u3067\u306e DI(Dependency Injection) \u304a\u3088\u3073 CDI(Contexts and Dependency Injection)\u3092\u306a\u304c\u3081\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/08\/java_ee_7_5_jboss_toolscdi\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(5) JBoss Tools\u304c\u751f\u6210\u3057\u305f\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u306eCDI\u3092\u78ba\u8a8d\u3059\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/10\/java_ee_7_6_jpa\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(6) JPA \u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306e\u4f5c\u6210\u3068\u633f\u5165<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/12\/java_ee_7_7_jpa_1\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(7) JPA \u554f\u3044\u5408\u308f\u305b(1) \u540d\u524d\u4ed8\u304d\u30af\u30a8\u30ea\u3092\u4f7f\u3063\u3066\u307f\u308b\u3002\u30c6\u30b9\u30c8\u3067\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3082\u610f\u8b58\u3059\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/17\/java_ee_7_8_jpa_2_criteria_api\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(8) JPA \u554f\u3044\u5408\u308f\u305b(2) \u52d5\u7684\u30af\u30a8\u30ea\u3068Criteria API \u3092\u8a66\u3059<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/25\/java_ee_7_9_jbatch\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(9) jBatch \u6982\u8981\u3092\u304a\u3055\u3048\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/25\/java_ee_7_10_jboss_tools_earjava_ee_6_7\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(10) JBoss Tools \u3067\u4f5c\u6210\u3057\u305f EAR\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092Java EE 6 \u304b\u3089 7 \u306b\u5909\u66f4\u3059\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/30\/java_ee_7_11_jbatch\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(11) jBatch\u7528 \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210\u3092\u884c\u3046<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/02\/java_ee_7_12_jbatch_arquillian\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(12) jBatch \u7c21\u6613\u30b5\u30f3\u30d7\u30eb\u4f5c\u6210\u3068 Arquillian \u3067\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/10\/java_ee_7_13_jbatch_rest\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(13) jBatch REST \u30b5\u30fc\u30d3\u30b9\u7d4c\u7531\u3067\u5b9f\u884c\u3059\u308b<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/15\/java_ee_7_14_wildfly_gui\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(14) WildFly \u306e\u7ba1\u7406\u3092GUI\u3067\u884c\u3046<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/15\/java_ee_7_15_wildfly_windowslinux\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(15) WildFly \u3092 \u30b5\u30fc\u30d3\u30b9\u3068\u3057\u3066\u8a2d\u5b9a\u3059\u308b(Windows\/Linux)<\/a><\/li>\n<li><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/06\/26\/java_ee_7_16_wildfly_apache_mod_jk_widows\">Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(16) WildFly \u3068 Apache \u3092 mod_jk \u3067\u9023\u643a\u3055\u305b\u308b(Widows)<\/a><\/li>\n<\/ol>\n<p>\u691c\u7d22\u6761\u4ef6\u304c\u9759\u7684\u306a\u30af\u30a8\u30ea\u306f\u3001<a href=\"https:\/\/www.typea.info\/blog\/index.php\/2014\/05\/12\/java_ee_7_7_jpa_1\">\u540d\u524d\u4ed8\u304d\u30af\u30a8\u30ea<\/a>\u3067\u5bfe\u5fdc\u51fa\u6765\u308b\u304c\u3001\u691c\u7d22\u753b\u9762\u306a\u3069\u8907\u6570\u306e\u691c\u7d22\u6761\u4ef6\u3092\u52d5\u7684\u306b\u7d44\u307f\u7acb\u3066\u308b\u5834\u5408\u306b\u306f\u5bfe\u5fdc\u51fa\u6765\u306a\u3044\u305f\u3081\u3001\u52d5\u7684\u306b\u30af\u30a8\u30ea\u3092\u7d44\u307f\u7acb\u3066\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304f\u308b\u3002<\/p>\n<p>SQL\u7d44\u307f\u7acb\u3066\u6761\u4ef6\u3092\u3001<a href=\"http:\/\/mybatis.github.io\/mybatis-3\/ja\/dynamic-sql.html\">XML\u3067\u6307\u5b9a\u3057\u305f\u308a<\/a>\u3001<a href=\"http:\/\/doma.seasar.org\/reference\/sqlfile.html\">SQL\u306e\u4e2d\u306b\u5f0f\u3092\u7d44\u307f\u8fbc\u3093\u3060\u308a<\/a>\u3068\u3001ORM\u30de\u30c3\u30d1\u30fc\u306e\u7a2e\u985e\u306b\u3088\u308a\u3044\u308d\u3044\u308d\u5bfe\u5fdc\u65b9\u6cd5\u304c\u3042\u308b\u304c\u3001JPA\u3067\u306f\u52d5\u7684\u306b\u30af\u30a8\u30ea\u6587\u5b57\u5217\u3092\u7d44\u307f\u7acb\u3066\u308b\u65b9\u6cd5\u3068\u3001Criteria API\u3092\u5229\u7528\u3057\u3066\u52d5\u7684\u306b\u30af\u30a8\u30ea\u3092\u7d44\u307f\u7acb\u3066\u308b\u65b9\u6cd5\u3068\u304c\u3042\u308b\u3002<\/p>\n<h2>1.\u52d5\u7684\u30af\u30a8\u30ea<\/h2>\n<ul>\n<li>\u52d5\u7684\u30af\u30a8\u30ea\u3092\u4f5c\u6210\u3059\u308b\u306e\u306b EntityManager.createQuery() \u3092\u4f7f\u7528\u3059\u308b<\/li>\n<li>\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306fJPQL\u30af\u30a8\u30ea\u3092\u8868\u3059\u6587\u5b57\u5217\u3092\u53d7\u3051\u53d6\u308b\n<ul>\n<li>Query query = em.createQuery(jpql);<\/li>\n<\/ul>\n<\/li>\n<li>\u578b\u4ed8\u3051\u3092\u884c\u3044\u305f\u3044\u5834\u5408\u3001TypedQuery\u3092\u5229\u7528\u3059\u308b\n<ul>\n<li>TypedQuery&lt;Book&gt; query = em.createQuery(jpql, Book.class);<\/li>\n<\/ul>\n<\/li>\n<li>\u540d\u524d\u4ed8\u304d\u3067\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6e21\u3059\u5834\u5408\u3001:parameterName \u3067\u5ba3\u8a00\u3057\u3001query.setParameter(&#8220;parameterName&#8221;,parameterValue) \u3067\u5024\u3092\u4e0e\u3048\u308b<\/li>\n<li>\u4f4d\u7f6e\u6307\u5b9a\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6e21\u3059\u5834\u5408\u3001?1 \u3067\u5ba3\u8a00\u3057\u3001query.setParameter(1, parameterValue) \u3067\u5024\u3092\u4e0e\u3048\u308b<\/li>\n<li><a href=\"http:\/\/docs.oracle.com\/javaee\/7\/tutorial\/doc\/persistence-querylanguage005.htm\">JPQL\u30af\u30a8\u30ea\u6587\u6cd5<\/a><\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u5b9f\u969b\u306b\u8a66\u3057\u3066\u307f\u308b\u3002\u307e\u3041\u306a\u3093\u3068\u3044\u3046\u304b\u3001\u6614\u306a\u304c\u3089\u306e\u611a\u76f4\u306a\u65b9\u6cd5\u3067\u306f\u3042\u308b\u3002<\/p>\n<p>\u3053\u306e\u4f8b\u3082\u3001\u52d5\u7684\u306b\u304f\u3081\u308b\u3088\u306d\u3068\u3044\u3046\u8996\u70b9\u306e\u307f\u3067\u3001\u52d5\u304b\u3059\u3053\u3068\u306e\u307f\u3092\u524d\u63d0\u306b\u4f5c\u6210\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u5b9f\u969b\u306b\u306f\u3082\u3046\u5c11\u3057\u6a5f\u80fd\u306e\u5171\u901a\u5316(\u4f8b\u3048\u3070\u3001\u6c4e\u7528\u7684\u306b\u6761\u4ef6\u3092\u7d44\u307f\u7acb\u3066\u308b\u3068\u304b\u3001\u30da\u30fc\u30b8\u30f3\u30b0\u3068\u304b)\u3068\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u304c\u5fc5\u8981\u3002<\/p>\n<p>\u66f8\u304d\u65b9\u3082\u3001JPQL\u3068\u3057\u3066\u306e\u898b\u901a\u3057\u304c\u3082\u3046\u5c11\u3057\u3088\u304f\u306a\u308b\u3088\u3046\u306a\u5de5\u592b\u3082\u5fc5\u8981\u3060\u308d\u3046\u3002<\/p>\n<p>\u3068\u306f\u3044\u3048\u3001\u3068\u308a\u3042\u3048\u305a\u610f\u56f3\u3057\u305f\u3088\u3046\u306b\u306f\u52d5\u304f\u3002\u307e\u305f\u3001\u30cd\u30a4\u30c6\u30a3\u30d6\u306aSQL\u3092\u7d44\u307f\u7acb\u3066\u3066\u3001\u305d\u308c\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3082\u5f53\u7136\u51fa\u6765\u308b\u3002<\/p>\n<pre class=\"prettyprint linenums\">public List<book> selectBooksByCondition(\r\n        String title, \r\n        Float price, \r\n        String description,\r\n        String isbn) {\r\n\r\n    int condCnt = 0;\r\n    Map<string object=\"\"> parameterMap = new HashMap<string object=\"\">();\r\n    StringBuilder buf = new StringBuilder();\r\n    \r\n    buf.append(\"select b from Book b\");\r\n    if (title != null ||\r\n        price != null ||\r\n        description != null || \r\n        isbn != null){\r\n    \r\n        buf.append(\" where\");\r\n        \r\n        if (title != null) {\r\n            buf.append(((condCnt++ == 0)?\"\":\" and\"));\r\n            buf.append(\" title like :title\");\r\n            parameterMap.put(\"title\", title + \"%\");\r\n        }\r\n        \r\n        if (price != null) {\r\n            buf.append(((condCnt++ == 0)?\"\":\" and\"));\r\n            buf.append(\" price = :price\");\r\n            parameterMap.put(\"price\", price);\r\n        }\r\n\r\n        if (description != null) {\r\n            buf.append(((condCnt++ == 0)?\"\":\" and\"));\r\n            buf.append(\" description like :description\");\r\n            parameterMap.put(\"description\", \"%\" + description + \"%\");\r\n        }\r\n\r\n        if (isbn != null) {\r\n            buf.append(((condCnt++ == 0)?\"\":\" and\"));\r\n            buf.append(\" isbn = :isbn\");\r\n            parameterMap.put(\"isbn\", isbn);\r\n        }\r\n    \r\n    }\r\n\r\n    \/\/Query query = em.createQuery(buf.toString());\r\n    TypedQuery<book> query = em.createQuery(buf.toString(), Book.class);\r\n    if (parameterMap.size() &gt; 0) {\r\n        for(Map.Entry<string object=\"\"> entry : parameterMap.entrySet()) {\r\n            query.setParameter(entry.getKey(), entry.getValue());\r\n        }\r\n    }\r\n\r\n    return query.getResultList();\r\n}<\/string><\/book><\/string><\/string><\/book><\/pre>\n<\/p>\n<h2>2.Criteria API(\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u30af\u30a8\u30ea)<\/h2>\n<ul>\n<li>\u6587\u5b57\u5217\u3067\u6307\u5b9a\u3059\u308b\u30af\u30a8\u30ea\u306f\u9593\u9055\u3048\u3084\u3059\u304f\u3001\u5b9f\u884c\u6642\u306b\u691c\u51fa\u3055\u308c\u308b\u305f\u3081\u539f\u56e0\u306e\u7279\u5b9a\u304c\u56f0\u96e3\u3068\u306a\u308b<\/li>\n<li>JPA2.0\u304b\u3089 Criteria API \u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u6b63\u3057\u3044\u30af\u30a8\u30ea\u69cb\u6587\u3092\u8a18\u8ff0\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304a\u308a\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u30a8\u30e9\u30fc\u3092\u691c\u51fa\u51fa\u6765\u308b<\/li>\n<li>Criteria API\u306fJPQL\u3067\u51fa\u6765\u308b\u3053\u3068\u304c\u3059\u3079\u3066\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b<\/li>\n<li><a href=\"http:\/\/docs.oracle.com\/javaee\/7\/tutorial\/doc\/persistence-criteria003.htm\">\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/a><\/li>\n<\/ul>\n<p>\u3067\u3001\u4e0a\u8a18\u3067\u52d5\u7684\u306bJPQL\u3092\u4f5c\u6210\u3057\u3066\u307f\u305f\u304c\u3001\u540c\u69d8\u306a\u3053\u3068\u3092\u3001Criteriap API \u3092\u4f7f\u7528\u3057\u3066\u3001\u30bf\u30a4\u30d7\u30bb\u30fc\u30d5\u306b\u884c\u3046\u3053\u3068\u3082\u304c\u3067\u304d\u308b\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u3068\u3057\u3066\u306f\u3001\u3053\u3061\u3089\u306e\u65b9\u304c\u3059\u3063\u304d\u308a\u3057\u3066\u306f\u3044\u308b\u304c\u3001\u3084\u306f\u308a\u3001\u3053\u306eAPI\u306e\u6319\u52d5\u3092\u77e5\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002\u3042\u308b\u7a0b\u5ea6\u8907\u96d1\u306aSQL\u3092\u3001Criteria API\u306b\u7ffb\u8a33\u3057\u3066\u5b9f\u88c5\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u3044\u3057\u3001\u4e00\u65e6\u7ffb\u8a33\u3059\u308b\u3068\u3001\u5143\u306eSQL\u306f\u30d7\u30ed\u30c0\u30af\u30c8\u30b3\u30fc\u30c9\u3067\u306f\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u3057\u3002\u3002\u3002<\/p>\n<p>\u4e00\u6982\u306b\u3001Criteria API \u306e\u65b9\u304c\u3001\u52d5\u7684\u30af\u30a8\u30ea\u3088\u308a\u3088\u3044\u3068\u306f\u8a00\u3044\u304c\u305f\u3044\u3068\u3053\u308d\u3082\u3042\u308b\u3002<\/p>\n<pre class=\"prettyprint linenums\">public List&lt;book&gt; selectBooksByCondition2(\r\n        String title, \r\n        Float price, \r\n        String description,\r\n        String isbn) {        \r\n\r\n    CriteriaBuilder builder = em.getCriteriaBuilder();\r\n    CriteriaQuery&lt;book&gt; query = builder.createQuery(Book.class);\r\n    \r\n    Root&lt;book&gt; book = query.from(Book.class);\r\n    \r\n    query.select(book);\r\n   \r\n    List&lt;predicate&gt; creteria = new ArrayList&lt;predicate&gt;();\r\n        \r\n    if (title != null) {\r\n        creteria.add(builder.like(book.&lt;string&gt;get(\"title\"), title + \"%\"));\r\n    }\r\n    \r\n    if (price != null) {\r\n        creteria.add(builder.equal(book.&lt;float&gt;get(\"price\"), price));\r\n    }\r\n\r\n    if (description != null) {\r\n        creteria.add(builder.like(book.&lt;string&gt;get(\"description\"), \"%\"+description+\"%\"));\r\n    }\r\n\r\n    if (isbn != null) {\r\n        creteria.add(builder.equal(book.&lt;string&gt;get(\"isbn\"), isbn));\r\n    }\r\n    \r\n    if (creteria.size() &gt; 0) {\r\n        query.where(builder.and(creteria.toArray(new Predicate[]{})));\r\n    }\r\n    \r\n    return em.createQuery(query).getResultList();\r\n}<\/pre>\n<\/p>\n<h3>\u30bf\u30a4\u30d7\u30bb\u30fc\u30d5\u306aCriteria API<\/h3>\n<ul>\n<li><a href=\"http:\/\/hibernate.org\/orm\/tooling\/\">Hibernate \u30e1\u30bf\u30e2\u30c7\u30eb\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf<\/a><\/li>\n<\/ul>\n<p>\u4e0a\u8a18\u3001Criteria API \u3067\u306f\u3001\u30af\u30a8\u30ea\u306e\u69cb\u7bc9\u306f\u78ba\u304b\u306b\u30bf\u30a4\u30d7\u30bb\u30fc\u30d5\u3068\u306a\u3063\u3066\u3044\u308b\u304c\u3001\u30e2\u30c7\u30eb\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u30a2\u30af\u30bb\u30b9\u306b\u306f\u3001\u6587\u5b57\u5217\u3092\u4f7f\u3063\u3066\u3044\u308b\u305f\u3081\u30bf\u30a4\u30d7\u30bb\u30fc\u30d5\u3068\u306f\u8a00\u3044\u304c\u305f\u3044\u3002\u578b\u3082\u81ea\u3089\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>JPA\u3067\u306f\u3001\u30e1\u30bf\u30e2\u30c7\u30eb\u3092\u5b9a\u7fa9\u3067\u304d\u3001\u4ee5\u4e0b\u306e\u69d8\u306bCriteria API \u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3002<\/p>\n<p><a title=\"http:\/\/relation.to\/Bloggers\/HibernateStaticMetamodelGeneratorAnnotationProcessor\" href=\"http:\/\/relation.to\/Bloggers\/HibernateStaticMetamodelGeneratorAnnotationProcessor\">http:\/\/relation.to\/Bloggers\/HibernateStaticMetamodelGeneratorAnnotationProcessor<\/a><\/p>\n<p>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3<\/p>\n<pre class=\"prettyprint linenums\">@Entity public class Order {\r\n    @Id \r\n    Integer id;\r\n    @ManyToOne \r\n    Customer customer;\r\n    @OneToMany \r\n    Set<item> items;\r\n    BigDecimal totalCost;\r\n    ...\r\n}<\/item><\/pre>\n<p>\u30e1\u30bf\u30e2\u30c7\u30eb<\/p>\n<pre class=\"prettyprint linenums\">@StaticMetamodel(Order.class)\r\npublic class Order_ {\r\n    public static volatile SingularAttribute<order integer=\"\"> id;\r\n    public static volatile SingularAttribute<order customer=\"\"> customer;\r\n    public static volatile SetAttribute<order item=\"\"> items;\r\n    public static volatile SingularAttribute<order bigdecimal=\"\"> totalCost;\r\n}<\/order><\/order><\/order><\/order><\/pre>\n<p>\u30af\u30a8\u30ea<\/p>\n<pre class=\"prettyprint linenums\">CriteriaBuilder cb = ordersEntityManager.getCriteriaBuilder();\r\nCriteriaQuery<order> cq = cb.createQuery(Order.class);\r\nSetJoin<order item=\"\"> itemNode = cq.from(Order.class)\r\n\t.join(Order_.orderItems);\r\ncq.where( cb.equal(itemNode.get(Item_.id), 5 ) ) \r\n\t.distinct(true);<\/order><\/order><\/pre>\n<p>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u578b\u6307\u5b9a\u3068\u3001\u578b\u540d\u306e\u6587\u5b57\u5217\u3092\u30af\u30a8\u30ea\u3067\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u4e0d\u8981\u306b\u306a\u3063\u3066\u3044\u308b\u3002\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3+&#8221;_&#8221;\u304c\u30e1\u30bf\u60c5\u5831\u3092\u7ba1\u7406\u3057\u3066\u3044\u308b\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u3053\u306e\u30e1\u30bf\u30e2\u30c7\u30eb\u306e\u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u306e\u691c\u7d22\u6761\u4ef6\u3092\u30bf\u30a4\u30d7\u30bb\u30fc\u30d5\u306b\u30af\u30a8\u30ea\u306b\u843d\u3068\u3057\u8fbc\u3080\u5171\u901a\u51e6\u7406\u304c\u304b\u3051\u305d\u3046\u3060\u306a\u30fc\u3068\u304b\u601d\u3044\u306a\u304c\u3089\u3001\u30e1\u30bf\u30e2\u30c7\u30eb\u3092Eclipse+JBoss Tools \u4e0a\u3067\u7c21\u5358\u306b\u81ea\u52d5\u751f\u6210\u3059\u308b\u624b\u9806\u304c\u3088\u304f\u308f\u304b\u3089\u306a\u3044\u306e\u3067\u3001\u4eca\u5f8c\u306e\u8ab2\u984c\u3002<\/p>\n<p>\n<iframe loading=\"lazy\" width=\"320\" height=\"240\" style=\"height: 240px; width: 120px;\" marginheight=\"0\" src=\"http:\/\/rcm-fe.amazon-adsystem.com\/e\/cm?lt1=_blank&amp;bc1=FFFFFF&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=typea09-22&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=ss_til&amp;asins=4798124605\" frameborder=\"0\" marginwidth=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(1) WildFly + JBoss Tools \u3067 EAR\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057 Arquillian \u3067 \u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u30b0\u30ea\u30fc\u30f3\u306b\u3059\u308b\u3068\u3053\u308d\u307e\u3067 Java EE 7 \u691c\u8a3c\u74b0\u5883\u69cb\u7bc9(2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[46,72],"tags":[],"class_list":["post-402","post","type-post","status-publish","format-standard","hentry","category-java-ee","category-jpa"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=402"}],"version-history":[{"count":0,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/402\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}