{"id":4194,"date":"2014-03-30T09:10:20","date_gmt":"2014-03-30T09:10:20","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/hibernate-one-to-one-mapping-with-interface-i-need-advice-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:10:20","modified_gmt":"2014-03-30T09:10:20","slug":"hibernate-one-to-one-mapping-with-interface-i-need-advice-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/hibernate-one-to-one-mapping-with-interface-i-need-advice-collection-of-common-programming-errors\/","title":{"rendered":"Hibernate One-to-one Mapping with interface.i need advice-Collection of common programming errors"},"content":{"rendered":"<p>hello good people i&#8217;m developping an application where all the pojos are exposed as interface but we map the real implementation class.we are using spring and JPA annotation.i&#8217;m about to test the one-to-one relationship and i&#8217;m having a light problem with the interface.<\/p>\n<blockquote>\n<p>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#8216;sessionContainer&#8217; defined in class path resource [META-INF\/model-config.xml]: Cannot resolve reference to bean &#8216;sessionFactory&#8217; while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#8216;sessionFactory&#8217; defined in class path resource [META-INF\/model-config.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException:<\/p>\n<p>@OneToOne or @ManyToOne on com.mycompany.project.subproject.model.UserAccountImpl.profile references an unknown entity: com.mycompany.project.<\/p>\n<\/blockquote>\n<p>so before this class all the other mapped class are working as expected so i&#8217;ll only post part of the <code>applicationContext<\/code> file that i named <code>model-config.xml<\/code><\/p>\n<pre><code>\n        \n            ${hibernate.dialect}\n            ${hibernate.show_sql}\n            ${hibernate.hbm2ddl.auto}\n            ${hibernate.format_sql}\n        \n    \n    \n        \n           ...\n            com.mycompany.project.subproject.model.UserProfileImpl\n            com.mycompany.project.subproject.model.UserAccountImpl\n           ...\n        \n    \n<\/code><\/pre>\n<p>here are the two involved class <code>UserProfileImpl.java<\/code> and <code>UserAccountImpl.java<\/code><\/p>\n<pre><code>\/\/UserAccountImpl Class\n@Entity\n@Table(name =\"USER_ACCOUNT\")\npublic class UserAccountImpl implements UserAccount {\n\n  @Id @GeneratedValue\n  @Column(name=\"USER_ACCOUNT_ID\")\n  private Long ID;\n\n  ...\n\n  @OneToOne\n  @JoinColumn(name=\"USER_PROFILE_ID\")\n  private UserProfile profile;\n\n  ...\n }\n\n\/\/UserProfileImpl class\n@Entity\n@Table(name=\"USER_PROFILE\")\npublic class UserProfileImpl implements UserProfile {\n\n @Id @GeneratedValue\n @Column(name=\"USER_PROFILE_ID\")\n private Long ID;\n ....\n\n @OneToOne(mappedBy=\"profile\")\n private UserAccount userAccount;\n ....\n<\/code><\/pre>\n<p>}<\/p>\n<p>i&#8217;m still not very confortable with hibernate yet so i&#8217;m wondering if i should Change the <code>UserProfile<\/code> reference in <code>UserAccountImpl<\/code> to <code>UserProfileImpl<\/code>.Then again the same can happen in the <code>UserProfileImpl<\/code> for <code>userAccount<\/code> reference since it&#8217;s a bidirectional navigation stuff. What&#8217;s the best option that will no break the consistency of the structure? Thanks for reading this<\/p>\n","protected":false},"excerpt":{"rendered":"<p>hello good people i&#8217;m developping an application where all the pojos are exposed as interface but we map the real implementation class.we are using spring and JPA annotation.i&#8217;m about to test the one-to-one relationship and i&#8217;m having a light problem with the interface. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#8216;sessionContainer&#8217; defined in class [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4194","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4194"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4194\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}