{"id":25,"date":"2005-09-08T17:07:10","date_gmt":"2005-09-08T16:07:10","guid":{"rendered":"http:\/\/www.epischel.de\/wordpress\/?p=25"},"modified":"2009-10-21T21:49:18","modified_gmt":"2009-10-21T20:49:18","slug":"hibernate-a-developers-notebook-migrating-to-hibernate-30-chapter-3","status":"publish","type":"post","link":"https:\/\/www.epischel.de\/wordpress\/2005\/09\/hibernate-a-developers-notebook-migrating-to-hibernate-30-chapter-3\/","title":{"rendered":"&#8222;Hibernate &#8211; A Developers Notebook&#8220; &#8211; migrating to Hibernate 3.0, Chapter 3"},"content":{"rendered":"<p>In chapter 3 (you can <a href=\"http:\/\/www.oreilly.com\/catalog\/hibernate\/chapter\/ch03.pdf\">read it online<\/a>) we use the Track table to insert some data and to query data.<\/p>\n<p>We use CreateTest to create and QueryTest to query data. Some simple adaptions are necessary:<\/p>\n<ul>\n<li>change package name of hibernate classes to org.hibernate<\/li>\n<li>replace the use of the all-attributes-as-parameters-constructor with Java-Bean style use of empty constructors and setters<\/li>\n<li>change the type of &#8222;volume&#8220; attribute from short to java.lang.Short<\/li>\n<\/ul>\n<p>Here is the changed part of CreateTest.java:<\/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\">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\"><span style=\"color: #003399\">Track<\/span> track <span style=\"color: #339933\">=<\/span> <span style=\"color: #000000;font-weight: bold\">new<\/span> <span style=\"color: #003399\">Track<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setTitle<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;Russian Trance&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setFilePath<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;vol2\/album610\/track02.mp3&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setPlayTime<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #003399\">Time<\/span>.<span style=\"color: #006633\">valueOf<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;00:03:30&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setAdded<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000000;font-weight: bold\">new<\/span> <span style=\"color: #003399\">Date<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setVolume<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000000;font-weight: bold\">new<\/span> <span style=\"color: #003399\">Short<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000066;font-weight: bold\">short<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #cc66cc\">0<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><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;session.<span style=\"color: #006633\">save<\/span><span style=\"color: #009900\">&#040;<\/span>track<span style=\"color: #009900\">&#041;<\/span><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;<\/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;track <span style=\"color: #339933\">=<\/span> <span style=\"color: #000000;font-weight: bold\">new<\/span> <span style=\"color: #003399\">Track<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setTitle<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;Video Killed the Radio Star&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setFilePath<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;vol2\/album611\/track12.mp3&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setPlayTime<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #003399\">Time<\/span>.<span style=\"color: #006633\">valueOf<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;00:03:49&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setAdded<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000000;font-weight: bold\">new<\/span> <span style=\"color: #003399\">Date<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setVolume<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000000;font-weight: bold\">new<\/span> <span style=\"color: #003399\">Short<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000066;font-weight: bold\">short<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #cc66cc\">0<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><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;session.<span style=\"color: #006633\">save<\/span><span style=\"color: #009900\">&#040;<\/span>track<span style=\"color: #009900\">&#041;<\/span><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;<\/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;track <span style=\"color: #339933\">=<\/span> <span style=\"color: #000000;font-weight: bold\">new<\/span> <span style=\"color: #003399\">Track<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setTitle<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;Gravity's Angel&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setFilePath<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;vol2\/album175\/track03.mp3&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setPlayTime<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #003399\">Time<\/span>.<span style=\"color: #006633\">valueOf<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">&quot;00:06:06&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setAdded<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000000;font-weight: bold\">new<\/span> <span style=\"color: #003399\">Date<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><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;track.<span style=\"color: #006633\">setVolume<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000000;font-weight: bold\">new<\/span> <span style=\"color: #003399\">Short<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000066;font-weight: bold\">short<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #cc66cc\">0<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #009900\">&#041;<\/span><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;session.<span style=\"color: #006633\">save<\/span><span style=\"color: #009900\">&#040;<\/span>track<span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>QueryTest needs only substitution of hibernate package names.<\/p>\n<p>I also created a ant-target called &#8222;clean-db&#8220; which deletes the entire schema in order to avoid multiple insertion of the same data as well as an ant-target called &#8222;clean&#8220; which simply deletes the &#8222;classes&#8220;-folder.<\/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;target<\/span> <span style=\"color: #000066\">name<\/span>=<span style=\"color: #ff0000\">&quot;clean-db&quot;<\/span> <span style=\"color: #000066\">description<\/span>=<span style=\"color: #ff0000\">&quot;deletes schema of DB.&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; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;delete<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;fileset<\/span> <span style=\"color: #000066\">dir<\/span>=<span style=\"color: #ff0000\">&quot;${data.dir}&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;include<\/span> <span style=\"color: #000066\">name<\/span>=<span style=\"color: #ff0000\">&quot;**\/*&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; <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; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;\/delete<span style=\"color: #000000;font-weight: bold\">&gt;<\/span><\/span><\/span> &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; <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<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; <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;clean&quot;<\/span> <span style=\"color: #000066\">description<\/span>=<span style=\"color: #ff0000\">&quot;clean ${class.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; <span style=\"color: #009900\"><span style=\"color: #000000;font-weight: bold\">&lt;delete<\/span> <span style=\"color: #000066\">dir<\/span>=<span style=\"color: #ff0000\">&quot;${class.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; <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>So now you can say<\/p>\n<pre>\r\n  ant clean-db clean schema codegen ctest qtest\r\n<\/pre>\n<p>and you get a clean db with a new schema, freshly generated code, test data generation and query test &#8211; in one command.<\/p>\n<div class=\"syndication-links\"><\/div>","protected":false},"excerpt":{"rendered":"<p>In chapter 3 (you can read it online) we use the Track table to insert some data and to query data. We use CreateTest to create and QueryTest to query data. Some simple adaptions are necessary: change package name of hibernate classes to org.hibernate replace the use of the all-attributes-as-parameters-constructor with Java-Bean style use of&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-25","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\/25","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=25"}],"version-history":[{"count":2,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/posts\/25\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/tags?post=25"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.epischel.de\/wordpress\/wp-json\/wp\/v2\/series?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}