{"componentChunkName":"component---node-modules-gatsby-theme-medium-to-own-blog-src-templates-blog-post-js","path":"/some-(n)hibernate-learnings/","result":{"data":{"site":{"siteMetadata":{"siteUrl":"https://javame.netlify.app","githubUrl":"https://github.com/aterreno/blog"}},"mdx":{"fields":{"slug":"/some-(n)hibernate-learnings/"},"excerpt":"After at least two years of Hibernate and NHibernate experience I can say that I know what’s going on, I can’t still say that I know very…","timeToRead":2,"frontmatter":{"title":"Some (N)Hibernate Learnings","description":"","categories":[],"date":"February 12, 2008","canonical_link":"https://javame.netlify.app//some-n-hibernate-learnings-7d83fe88df2c"},"body":"function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"Some (N)Hibernate Learnings\",\n  \"description\": \"\",\n  \"date\": \"2008-02-12T00:00:00.000Z\",\n  \"categories\": [],\n  \"published\": true,\n  \"canonical_link\": \"https://javame.netlify.app//some-n-hibernate-learnings-7d83fe88df2c\",\n  \"redirect_from\": [\"/some-n-hibernate-learnings-7d83fe88df2c\"]\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, [\"components\"]);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"After at least two years of Hibernate and NHibernate experience I can say that I know what\\u2019s going on, I can\\u2019t still say that I know very well (N)Hibernate but I wanna share some learnings.\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"The logger is your best friend:\", mdx(\"br\", {\n    parentName: \"li\"\n  }), \"When sometimes goes wrong, the logger (or at least a profiler) will help you, it\\u2019s awesome to play with a database like we play with objects but I have the feeling that sometimes we forget that on a couple of layers below we are doing some good old SQL!\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"(N)Hibernate is not meant for:\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Bulk data manipulations: use \", mdx(\"a\", _extends({\n    parentName: \"li\"\n  }, {\n    \"href\": \"http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx\",\n    \"target\": \"_blank\",\n    \"rel\": \"nofollow noopener noreferrer\"\n  }), \"sqlBulkCopy\"), \" in (.net) or upgrade to a version > 3.1.1 on Java Hibernate\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Free developers from understanding the database: it\\u2019s nice to hide the DB structure but the DB is there, and it\\u2019s not OO!\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Free developers from understanding (N)Hibernate.\\xA0\", mdx(\"br\", {\n    parentName: \"li\"\n  }), \"I sow many times in developers this approach: entusiasm followed by criticism followed by hate\\xA0:-) It\\u2019s very easy to do simple things and terrible then to fix bugs or understand some stack traces. It\\u2019s a great library and it\\u2019s not easy to use. A copy of \", mdx(\"a\", _extends({\n    parentName: \"li\"\n  }, {\n    \"href\": \"http://books.google.com/books?q=hibernate+in+action&btnG=Search+Books\",\n    \"target\": \"_blank\",\n    \"rel\": \"nofollow noopener noreferrer\"\n  }), \"hibernate in action\"), \" or of \", mdx(\"a\", _extends({\n    parentName: \"li\"\n  }, {\n    \"href\": \"http://books.google.com/books?q=nhibernate+in+action&btnG=Search+Books\",\n    \"target\": \"_blank\",\n    \"rel\": \"nofollow noopener noreferrer\"\n  }), \"nhibernate in action\"), \" should be always present in a team playing with it.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Let you forget the profiler: as mentioned before it\\u2019s the best way to understand the complexity of your queries, it\\u2019s easy to end up with a cartesian product result from a query or execute unuseful queries, especially when playing with multiple joins and criteria queries.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Do not generate queries using dynamic strings: queries compilations are cached (similar to query plans), it\\u2019s a nice and useful feature, especially talking about performances. Use parameters to allow reuse of query plans.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Lazy loading: if you don\\u2019t use lazy loading (default now) you\\u2019ll end up having all the DB in Memory, if you use lazy loading you might have the select N+1 problem\\u2026\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Usage patterns: session per request (good for webpages, opening the session on request start, dispose on request end) Vs the session per conversation, good for rich client application. I\\u2019ve the impression that in this second case you loose a lot of the hibernate power\\u2026\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Bags, lists, sets\\u2026\\xA0: choice is yours but keep in mind that especially in a domain driven design you could have some problems having methods playing with (lazy) collections in the POJO/POCO objects. And the cost of changing from one mapping strategy to a different one can be high.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Optimization: you\\u2019ll have performance problems, it\\u2019s sure, you\\u2019ll have it, I don\\u2019t believe in preemptive optimization but an eye on the profiler and one on the integration tests timings could help you to find earlier problems that you\\u2019ll see otherwise when it\\u2019s too late (i.e. in production!)\")));\n}\n;\nMDXContent.isMDXComponent = true;"},"allWebMentionEntry":{"nodes":[]}},"pageContext":{"id":"7612bc04-7ce6-5496-82bf-2e5dddcfc3e9","previous":{"id":"0b2218f7-d533-5fd9-8e76-c0e7ad5f2a52","fields":{"slug":"/don't-call-them-phones-the-g-phone-and-i-phone-battle/","published":true},"frontmatter":{"redirect_from":["/dont-call-them-phones-the-g-phone-and-i-phone-battle-44349ae1d51d"],"redirect_to":null,"title":"don’t call them phones, the g-phone and i-phone battle"}},"next":{"id":"c82cecaf-5cd3-54a3-ae3d-2404a4c84c84","fields":{"slug":"/bye-bye-london/","published":true},"frontmatter":{"redirect_from":["/bye-bye-london-3ca02b56c865"],"redirect_to":null,"title":"bye bye London"}},"permalink":"https://javame.netlify.app/some-(n)hibernate-learnings/","themeOptions":{"plugins":[],"config":{"title":"Antonio Terreno","description":"Antonio Terreno's blog archive","shortBio":"","bio":"Principal Consultant at Equal Experts","author":"Antonio Terreno","githubUrl":"https://github.com/aterreno/blog","siteUrl":"https://javame.netlify.app/","social":{"twitter":"javame","medium":"","facebook":"","github":"aterreno","linkedin":"antonioterreno","instagram":"tritonitri"},"goatCounterCode":null}}}},"staticQueryHashes":["4131332129","645483741"]}