{"id":31,"date":"2010-03-28T20:26:49","date_gmt":"2010-03-28T18:26:49","guid":{"rendered":"http:\/\/www.pmannel.de\/wordpress\/?p=31"},"modified":"2011-01-08T17:38:41","modified_gmt":"2011-01-08T16:38:41","slug":"composite-pattern-mit-hibernate","status":"publish","type":"post","link":"https:\/\/www.pmannel.de\/wordpress\/?p=31","title":{"rendered":"Composite Pattern mit Hibernate"},"content":{"rendered":"<p>Problem: Wie kann man im B\u00e4ume mit \u201cEltern\u201d und \u201cKindern\u201d, also ein klassisches <a href=\"http:\/\/de.wikipedia.org\/wiki\/Kompositum_%28Entwurfsmuster%29\">Composite-Pattern <\/a> mit Hibernate abbilden? <\/strong><\/p>\n<p><strong>Meine L\u00f6sung:<\/strong><br \/>\n(Im Konkreten ging es um die Darstellung <a href=\"http:\/\/simap.europa.eu\/codes-and-nomenclatures\/codes-cpv\/codes-cpv_de.htm\">dieser <\/a>Codes mit <b style=\"color: black; background-color: rgb(160, 255, 255);\">Hibernate<\/b>, wobei ich momentan noch keine Angaben zur Performance im Vergleich zu einer Implementierung mit <a href=\"http:\/\/de.wikipedia.org\/wiki\/Nested_Sets\">Nested Sets<\/a> machen kann)<\/p>\n<pre class=\"brush:java\">\r\npublic class CpvCodes implements Serializable\r\n{\r\n\tprivate Integer id;\r\n\tprivate String code;\r\n\tprivate String name;\r\n\tprivate CpvCodes parent;\r\n\r\n\tSet children = new HashSet();\r\n\r\n\tpublic String getName()\r\n\t{\r\n\t\treturn name;\r\n\t}\r\n\tpublic void setName(String name)\r\n\t{\r\n\t\tthis.name = name;\r\n\t}\r\n\r\n\tpublic String getCode()\r\n\t{\r\n\t\treturn code;\r\n\t}\r\n\tpublic void setCode(String code)\r\n\t{\r\n\t\tthis.code = code;\r\n\t}\r\n\tpublic Integer getId()\r\n\t{\r\n\t\treturn id;\r\n\t}\r\n\tpublic void setId(Integer id)\r\n\t{\r\n\t\tthis.id = id;\r\n\t}\r\n\r\n\tpublic Set getChildren()\r\n\t{\r\n\t\treturn children;\r\n\t}\r\n\tpublic void setChildren(Set children)\r\n\t{\r\n\t\tthis.children = children;\r\n\t}\r\n\tpublic CpvCodes getParent()\r\n\t{\r\n\t\treturn parent;\r\n\t}\r\n\tpublic void setParent(CpvCodes parent)\r\n\t{\r\n\t\tthis.parent = parent;\r\n\t}\r\n}\r\n\r\n<\/pre>\n<pre class=\"brush:xml\">\r\n<hibernate-mapping package=\"de.test.db.domain\">\r\n    <class name=\"CpvCodes\" table=\"cpvcodes\" catalog=\"test\">  \r\n\r\n      \t<id name=\"id\" type=\"java.lang.Integer\">\r\n<column name=\"id\">\r\n\t\t<\/column>\r\n<property name=\"code\" type=\"string\">\r\n<column name=\"code\">\r\n\t\t<\/column>\r\n<property name=\"name\" type=\"string\">\r\n<column name=\"de_name\">\r\n\t\t<\/column>\r\n\r\n\t\t<set name=\"children\" inverse=\"true\" lazy=\"true\" cascade=\"save-update\">\r\n\t\t\t<key column=\"parent_sid\"><\/key>\r\n\t\t\t<one-to-many class=\"CpvCodes\">\r\n\r\n\t\t<\/one-to-many>\r\n\t\t<many-to-one name=\"parent\" column=\"parent_sid\" cascade=\"save-update\" class=\"CpvCodes\">\r\n\r\n    <\/many-to-one>\r\n<\/set>\r\n<\/property><\/property><\/id><\/class><\/hibernate-mapping>\r\n<\/pre>\n<p>Ich finde es nur seltsam, das es zu so einem (Standard-) Problem relativ wenig Infos von Hibernate und so viele Fragen dazu in diversen Hibernateforen gibt!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: Wie kann man im B\u00e4ume mit \u201cEltern\u201d und \u201cKindern\u201d, also ein klassisches Composite-Pattern mit Hibernate abbilden? Meine L\u00f6sung: (Im Konkreten ging es um die Darstellung dieser Codes mit Hibernate, wobei ich momentan noch keine Angaben zur Performance im Vergleich zu einer Implementierung mit Nested Sets machen kann) public class CpvCodes implements Serializable { private&#8230; <\/p>\n<div class=\"read-more\"><a href=\"https:\/\/www.pmannel.de\/wordpress\/?p=31\">Weiterlesen<\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[23,24,72],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-hibernate","tag-composite-pattern","tag-entwurfsmuster","tag-hibernate"],"_links":{"self":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=31"}],"version-history":[{"count":6,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":130,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions\/130"}],"wp:attachment":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}