{"id":24,"date":"2005-09-06T14:45:31","date_gmt":"2005-09-06T13:45:31","guid":{"rendered":"http:\/\/www.epischel.de\/wordpress\/?p=24"},"modified":"2009-10-21T21:47:59","modified_gmt":"2009-10-21T20:47:59","slug":"%e2%80%9chibernate-a-developers-notebook%e2%80%9d-migrating-to-hibernate-30-chapter-2","status":"publish","type":"post","link":"https:\/\/www.epischel.de\/wordpress\/2005\/09\/%e2%80%9chibernate-a-developers-notebook%e2%80%9d-migrating-to-hibernate-30-chapter-2\/","title":{"rendered":"&#8222;Hibernate &#8211; A Developers Notebook&#8220; &#8211; migrating to Hibernate 3.0, Chapter 2"},"content":{"rendered":"<p>This is chapter 2 of rewriting the examples of O&#8217;Reillys book &#8222;Hibernate &#8211; A Developers Notebook&#8220; for using <a href=\"http:\/\/www.hibernate.org\">Hibernate<\/a> 3.0 instead of Hibernate 2.x . To get the context, read <a href=\"http:\/\/www.epischel.de\/wordpress\/?p=23\">chapter 1<\/a>.<\/p>\n<p>The goal of chapter 2 is to write a hbm file for a single table, generating the corresponding java file and compile it.<\/p>\n<p>A main difference when using Hibernate 3.0 is the ant task definition for hbm2java. It now looks like this:<\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">xml<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"xml\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;taskdef<\/span> <span style=\"color: #000066\">name<\/span>=<span style=\"color: #ff0000\">&quot;hibernatetool&quot;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #000066\">classname<\/span>=<span style=\"color: #ff0000\">&quot;org.hibernate.tool.ant.HibernateToolTask&quot;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #000066\">classpathref<\/span>=<span style=\"color: #ff0000\">&quot;project.class.path&quot;<\/span><span style=\"color: #000000;font-weight: bold\">\/&gt;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;target<\/span> <span style=\"color: #000066\">name<\/span>=<span style=\"color: #ff0000\">&quot;codegen&quot;<\/span> <span style=\"color: #000066\">depends<\/span>=<span style=\"color: #ff0000\">&quot;prepare&quot;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #000066\">description<\/span>=<span style=\"color: #ff0000\">&quot;Generate Java source from the O\/R mapping files&quot;<\/span><span style=\"color: #000000;font-weight: bold\">&gt;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;hibernatetool<\/span> <span style=\"color: #000066\">destdir<\/span>=<span style=\"color: #ff0000\">&quot;${source.root}&quot;<\/span><span style=\"color: #000000;font-weight: bold\">&gt;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;configuration<\/span> <span style=\"color: #000066\">propertyFile<\/span>=<span style=\"color: #ff0000\">&quot;${source.root}\/hibernate.properties&quot;<\/span><span style=\"color: #000000;font-weight: bold\">&gt;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;fileset<\/span> <span style=\"color: #000066\">dir<\/span>=<span style=\"color: #ff0000\">&quot;${source.root}&quot;<\/span><span style=\"color: #000000;font-weight: bold\">&gt;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;include<\/span> <span style=\"color: #000066\">name<\/span>=<span style=\"color: #ff0000\">&quot;**\/*.hbm.xml&quot;<\/span><span style=\"color: #000000;font-weight: bold\">\/&gt;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;\/fileset<span style=\"color: #000000;font-weight: bold\">&gt;<\/span><\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;\/configuration<span style=\"color: #000000;font-weight: bold\">&gt;<\/span><\/span><\/span> &nbsp; &nbsp; &nbsp; &nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;hbm2java<\/span> <span style=\"color: #000000;font-weight: bold\">\/&gt;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; <\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp;<span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;\/hibernatetool<span style=\"color: #000000;font-weight: bold\">&gt;<\/span><\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp;<span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;\/target<span style=\"color: #000000;font-weight: bold\">&gt;<\/span><\/span><\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Also, the package-name of the schemaexport-task has changed:<\/p>\n<div id=\"ig-sh-2\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">xml<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"xml\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;taskdef<\/span> <span style=\"color: #000066\">name<\/span>=<span style=\"color: #ff0000\">&quot;schemaexport&quot;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #000066\">classname<\/span>=<span style=\"color: #ff0000\">&quot;org.hibernate.tool.hbm2ddl.SchemaExportTask&quot;<\/span><\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style=\"color: #000066\">classpathref<\/span>=<span style=\"color: #ff0000\">&quot;project.class.path&quot;<\/span><span style=\"color: #000000;font-weight: bold\">\/&gt;<\/span><\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Another difference is the jdbc-url for HSQLDB 1.8. You have to insert &#8222;file&#8220; as in:<\/p>\n<pre>\r\njdbc:hsqldb:file:${data.dir}\/music\r\n<\/pre>\n<p>(in ant task &#8222;db&#8220;) or<\/p>\n<pre>\r\njdbc:hsqldb:file:data\/music\r\n<\/pre>\n<p>in hibernate.properties<\/p>\n<p>I developed offline so I ran into the problem that the XML parser wants to download the mapping-dtd as advertised in the DOCTYPE-section of the hbm.xml file. I stripped off the http:\/\/www.hibernate.org part of the url, downloaded the dtd and placed it in the root-directory.<\/p>\n<p>After using Ant 1.6, everything worked fine. (Otherwise I got:<\/p>\n<div id=\"ig-sh-3\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">java<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"java\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">java.<span style=\"color: #006633\">lang<\/span>.<span style=\"color: #003399\">NoSuchMethodError<\/span><span style=\"color: #339933\">:<\/span> org.<span style=\"color: #006633\">apache<\/span>.<span style=\"color: #006633\">tools<\/span>.<span style=\"color: #006633\">ant<\/span>.<span style=\"color: #006633\">Project<\/span>.<span style=\"color: #006633\">createClassLoader<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; <span style=\"color: #009900\">&#040;<\/span>Lorg<span style=\"color: #339933\">\/<\/span>apache<span style=\"color: #339933\">\/<\/span>tools<span style=\"color: #339933\">\/<\/span>ant<span style=\"color: #339933\">\/<\/span>types<span style=\"color: #339933\">\/<\/span>Path<span style=\"color: #339933\">;<\/span><span style=\"color: #009900\">&#041;<\/span>Lorg<span style=\"color: #339933\">\/<\/span>apache<span style=\"color: #339933\">\/<\/span>tools<span style=\"color: #339933\">\/<\/span>ant<span style=\"color: #339933\">\/<\/span>AntClassLoader<span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; &nbsp; &nbsp; at org.<span style=\"color: #006633\">hibernate<\/span>.<span style=\"color: #006633\">tool<\/span>.<span style=\"color: #006633\">ant<\/span>.<span style=\"color: #006633\">HibernateToolTask<\/span>.<span style=\"color: #006633\">execute<\/span><span style=\"color: #009900\">&#040;<\/span>HibernateToolTask.<span style=\"color: #006633\">java<\/span><span style=\"color: #339933\">:<\/span><span style=\"color: #cc66cc\">113<\/span><span style=\"color: #009900\">&#041;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\">&#041;<\/span>...<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>The generated code reveals some differences:<\/p>\n<ul>\n<li>The type of the volume attribute is java.lang.Short, not short &#8222;as advertised&#8220;. This is because of the xml-attribute &#8222;not-null&#8220; set to null. However if you ommit this xml-attribute, java.lang.Short is used again.\n<\/li>\n<li>There is no all-attributes-as-parameters-constructor.<\/li>\n<li>\nThere is no equals and no hash-code implementation.<\/li>\n<\/ul>\n<p>I have not yet any idea about why&#8217;s that. Comments are welcome. Point 2 + 3 might be because different code templates.<\/p>\n<div class=\"syndication-links\"><\/div>","protected":false},"excerpt":{"rendered":"<p>This is chapter 2 of rewriting the examples of O&#8217;Reillys book &#8222;Hibernate &#8211; A Developers Notebook&#8220; for using Hibernate 3.0 instead of Hibernate 2.x . To get the context, read chapter 1. The goal of chapter 2 is to write a hbm file for a single table, generating the corresponding java file and compile it.&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"mf2_syndication":[],"webmentions_disabled_pings":false,"webmentions_disabled":false,"footnotes":""},"categories":[3],"tags":[23,24,120],"series":[],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-java","tag-bucher","tag-hibernate","tag-java","kind-"],"kind":false,"_links":{"self":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":2,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/24\/revisions\/173"}],"wp:attachment":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/tags?post=24"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/series?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}