{"id":2328,"date":"2017-05-21T17:59:12","date_gmt":"2017-05-21T17:59:12","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=2328"},"modified":"2017-06-02T08:18:06","modified_gmt":"2017-06-02T08:18:06","slug":"hibernate-errors","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/hibernate-errors\/","title":{"rendered":"Hibernate Errors"},"content":{"rendered":"<p><strong>org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class<\/strong><br \/>\n<strong>Sol<\/strong><\/p>\n<ol>\n<li>@Entity Should be added in the Model class <\/li>\n<li>If you have missed to add the Model class in the xml file<\/li>\n<li>Make sure the annotation is javax.persistence.Entity, and not org.hibernate.annotations.Entity. The former makes the entity detectable.<\/li>\n<\/ol>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n<strong>javax.naming.NoInitialContextException: Need to specify class name in environment or system property<\/strong><br \/>\n<strong>Sol<\/strong><br \/>\n&#8220;I want to find the telephone number for John Smith, but I have no phonebook to look in&#8221;.This exception is thrown when no initial context implementation can be created.JNDI (javax.naming) is all about looking up objects or resources from some directory or provider. To look something up, you need somewhere to look (this is the InitialContext).<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n<strong>hibernate exception: org.hibernate.AnnotationException: No identifier specified for entity<\/strong><br \/>\n<strong>Sol<\/strong> <\/p>\n<ol>\n<li>You are missing a field annotated with @Id. Each @Entity needs an @Id &#8211; this is the primary key in the database. <\/li>\n<li>If you don&#8217;t want your entity to be persisted in a separate table, but rather be a part of other entities, you can use @Embeddable instead of @Entity.<\/li>\n<li>If you want simply a data transfer object to hold some data from the hibernate entity, use no annotations on it whatsoever &#8211; leave it a simple pojo.<\/li>\n<\/ol>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n<strong>org.hibernate.hql.internal.ast.QuerySyntaxException: table is not mapped <\/strong><br \/>\n<strong>Sol<\/strong><br \/>\nIn the HQL , you should use the java class name and property name of the mapped @Entity instead of the actual table name and column name <\/p>\n<p>For example if your bean class name is UserDetails then the Hibernate code should be as below.Not  Tbl_UserDetails instead of UserDetails<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n Query query = entityManager. createQuery(&quot;Select UserName from UserDetails&quot;); \r\n<\/pre>\n<p>The problem can also be because of wrong import<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport javax.persistence.Entity;\r\n<\/pre>\n<p>instead of <\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport org.hibernate.annotations.Entity;\r\n<\/pre>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n","protected":false},"excerpt":{"rendered":"<p>org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class Sol @Entity Should be added in the Model class If you have missed to add the Model class in the xml file Make sure the annotation is javax.persistence.Entity, and not org.hibernate.annotations.Entity. The former makes the entity detectable. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- javax.naming.NoInitialContextException: Need to specify class name in&hellip; <a href=\"https:\/\/codethataint.com\/blog\/hibernate-errors\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[237],"tags":[],"class_list":["post-2328","post","type-post","status-publish","format-standard","hentry","category-errors-hibernate"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=2328"}],"version-history":[{"count":11,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2328\/revisions"}],"predecessor-version":[{"id":2359,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2328\/revisions\/2359"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=2328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=2328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=2328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}