-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Need help with a runtime error using Hibernate in a Java app
PostPosted: Thu Dec 17, 2009 1:13 am 
Newbie

Joined: Thu Dec 17, 2009 1:07 am
Posts: 1
Dear fellow Java developers:

I am getting a runtime error when I try to run my java application that uses hibernate. The error message I'm getting is:

org.hibernate.AnnotationException: No identifier specified for entity: com.searchqs.beans.Hadith

From my research on the web, I've found out that you get this error when you have not set @Id for one of your properties or fields. The thing is, I don't have a primary key in my table, so I'm wondering if it's still necessary to set this value as one of my annotations? If this is so, is there a workaround to this, or must I absolutely have a primary key, which I must map to a field using the @Id annotation? Just wondering. I've attached the class that maps to my table, along with the full stack trace below.

Thanks in advance to all who reply.

Code:
package com.searchqs.beans;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;


@Entity
@Table(name="hadith")
public class Hadith {
         
        @Column(name="collection")
        String collection;
         
        @Column(name="volume")
        int volume;
         
        @Column(name="booknumber")
        int bookNumber;
         
        @Column(name="booktitle")
        String bookTitle;
         
        @Column(name="chapternumber")
        int chapterNumber;
         
        @Column(name="chaptertitle")
        String chapterTitle;
         
        @Column(name="hadithnumber")
        int hadithNumber;
         
        @Column(name="hadithgrade")
        String hadithGrade;
         
        @Column(name="narrator")
        String narrator;
         
        @Column(name="matntext")
        String matnText;
         
         
        public String getCollection() {
                return collection;
        }
        public void setCollection(String collection) {
                this.collection = collection;
        }
        public int getVolume() {
                return volume;
        }
        public void setVolume(int volume) {
                this.volume = volume;
        }
        public int getBookNumber() {
                return bookNumber;
        }
        public void setBookNumber(int bookNumber) {
                this.bookNumber = bookNumber;
        }
        public String getBookTitle() {
                return bookTitle;
        }
        public void setBookTitle(String bookTitle) {
                this.bookTitle = bookTitle;
        }
        public int getChapterNumber() {
                return chapterNumber;
        }
        public void setChapterNumber(int chapterNumber) {
                this.chapterNumber = chapterNumber;
        }
        public String getChapterTitle() {
                return chapterTitle;
        }
        public void setChapterTitle(String chapterTitle) {
                this.chapterTitle = chapterTitle;
        }
        public int getHadithNumber() {
                return hadithNumber;
        }
        public void setHadithNumber(int hadithNumber) {
                this.hadithNumber = hadithNumber;
        }
        public String getHadithGrade() {
                return hadithGrade;
        }
        public void setHadithGrade(String hadithGrade) {
                this.hadithGrade = hadithGrade;
        }
        public String getNarrator() {
                return narrator;
        }
        public void setNarrator(String narrator) {
                this.narrator = narrator;
        }
        public String getMatnText() {
                return matnText;
        }
        public void setMatnText(String matnText) {
                this.matnText = matnText;
        }
         

}





Code:

javax.servlet.ServletException: Servlet execution threw an exception


root cause 

java.lang.ExceptionInInitializerError
        com.searchqs.utils.HibernateUtil.<clinit>(HibernateUtil.java:20)
        com.searchqs.DAO.HadithDAO.saveOrUpdate(HadithDAO.java:18)
        com.searchqs.controller.DataServlet.doPost(DataServlet.java:77)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

org.hibernate.AnnotationException: No identifier specified for entity: com.searchqs.beans.Hadith
        org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:672)
        org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
        org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
        org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
        org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
        com.searchqs.utils.HibernateUtil.<clinit>(HibernateUtil.java:15)
        com.searchqs.DAO.HadithDAO.saveOrUpdate(HadithDAO.java:18)
        com.searchqs.controller.DataServlet.doPost(DataServlet.java:77)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


Top
 Profile  
 
 Post subject: Re: Need help with a runtime error using Hibernate in a Java app
PostPosted: Thu Dec 17, 2009 11:01 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
yeah, you need a primary key in every table => you need to define which column(s) is/are the primary key. I would suggest another property Id that is generated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.