-->
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.  [ 4 posts ] 
Author Message
 Post subject: Annotations: org.hibernate.AnnotationException
PostPosted: Sat Nov 01, 2008 9:33 am 
Beginner
Beginner

Joined: Sat Oct 18, 2008 10:25 am
Posts: 30
Hi,

I used mapping-files in my application, but now I want to use annotations. I get following error:

Initial SessionFactory creation failed.org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)


I don't know, where my mistake is. Everything seems to be right.

Here are my classes:

Category.java


Code:
package de.waldhausweg7.model;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.validator.ValidatorException;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import com.icesoft.faces.component.ext.RowSelectorEvent;

import de.waldhausweg7.listener.BeanBase;
import de.waldhausweg7.listener.Listener;
import de.waldhausweg7.service.CategoryService;
import de.waldhausweg7.service.PersonService;

@Entity
@Table
public class Category extends BeanBase implements Listener {
   private int categoryId;
   private String categoryName;
   private String comment;
   
   // Konstruktoren.
   public Category(int categoryId, String categoryName) {
      this.categoryId = categoryId;
      this.categoryName = categoryName;
   }
   
   public Category() {
      
   }
   
   // Getter und Setter.
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)   
   public int getCategoryId() {
      return categoryId;
   }
   
   public void setCategoryId(int categoryId) {
      this.categoryId = categoryId;
   }
   
   public String getCategoryName() {
      return categoryName;
   }
   
   public void setCategoryName(String categoryName) {
      this.categoryName = categoryName;
   }
   
   public String getComment() {
      return comment;
   }

   public void setComment(String comment) {
      this.comment = comment;
   }
   
   // Vom Interface geerbte Methoden.
   public void add(ActionEvent actionEvent) {
      try {
         CategoryService.addCategory(this);
         this.setCategoryName("");
         this.setCategoryId(0);
         this.setComment("");
      } catch(Exception e) {

      }
      
   }

   public void delete(ActionEvent actionEvent) {
      try {
         CategoryService.deleteCategory(getCategoryId());
         setDisableEditButton(true);
         setDisableDeleteButton(true);
      } catch(Exception e) {
         
      }      
   }

   public void rowSelectionListener(RowSelectorEvent event) {
      try {
         CategoryService categoryService = new CategoryService();
         Category category = (Category)categoryService.getCategoryList().get(event.getRow());
         this.setCategoryId(category.getCategoryId());
         this.setCategoryName(category.getCategoryName());
         this.setComment(category.getComment());
         setDisableEditButton(false);
         setDisableDeleteButton(false);
      } catch (Exception e) {
         
      }
   }

   public String selectOutcomeAction() {
      // TODO Auto-generated method stub
      return null;
   }

   public void update(ActionEvent actionEvent) {
      try {
         CategoryService.updateCategory(this);
         setDisableEditButton(true);
         setDisableDeleteButton(true);
      } catch(Exception e) {

      }
   }

   public void validate(FacesContext context, UIComponent component,
         Object checkValue) throws ValidatorException {
      // TODO Auto-generated method stub
      
   }
}



My CategoryService.java

Code:
package de.waldhausweg7.service;


import java.util.List;

import org.hibernate.SQLQuery;
import org.hibernate.Session;

import de.waldhausweg7.model.Category;
import de.waldhausweg7.utils.HibernateUtil;
import de.waldhausweg7.utils.ServiceBase;


public class CategoryService extends ServiceBase {
   private List categoryList;

   // Service-Methoden.

   public static void addCategory(Category category) throws Exception {
      Session session = null;
      // Temporäre Stadt, damit man mit einem Objekt der Klasse Category arbeitet und nicht mit einem Objekt der Klasse
      // CategoryListener.
      Category categoryDB = new Category();
      categoryDB.setCategoryName(category.getCategoryName());   
      categoryDB.setComment(category.getComment());
      
      try {
         session = HibernateUtil.getSessionFactory().getCurrentSession();
         session.beginTransaction();
         session.save(categoryDB);
         session.flush();
         session.getTransaction().commit();
      }
      catch(Exception e) {
         throw new Exception(e);
      }
      finally {
         HibernateUtil.closeSession(session);
      }
   }


   public static void deleteCategory(int categoryId) throws Exception {
      Session session = null;

      try {   
         session = HibernateUtil.getSessionFactory().getCurrentSession();
         session.beginTransaction();
         Category category = (Category)session.get(Category.class, categoryId);
         if (category != null) {
            session.delete(category);
            session.flush();
         }
         session.getTransaction().commit();
      }
      catch(Exception e) {
         throw new Exception(e);
      }
      finally {
         HibernateUtil.closeSession(session);
      }
   }


   public static void updateCategory(Category category) throws Exception {
      Session session = null;

      try {
         session = HibernateUtil.getSessionFactory().getCurrentSession();
         session.beginTransaction();
         session.update(category);
         session.flush();
         session.getTransaction().commit();
      }
      catch(Exception e) {
         throw new Exception(e);
      }
      finally {
         HibernateUtil.closeSession(session);
      }
   }

   public List getCategoryList() throws Exception {
      Session session = null;
      // Gibt an, ob aufsteigend oder absteigend sortiert werden soll.
      String order;
      // Ermittelt, ob aufsteigend oder absteigend sortiert werden soll.
      if (isAscending() == true) {
         order = "asc";
      } else {
         order = "desc";
      }      

      try {
         session = HibernateUtil.getSessionFactory().getCurrentSession();
         session.beginTransaction();
         SQLQuery q = session.createSQLQuery("SELECT * FROM category order by " + getSortColumn() + " " + order);
         q.addEntity(Category.class);
         categoryList = q.list();
         session.getTransaction().commit();
         return categoryList;
      }
      catch(Exception e) {
         throw new Exception(e);
      }
      finally {
         HibernateUtil.closeSession(session);
      }
   }


   public static Category getCategory(String postalCode) throws Exception {
      Session session = null;

      try {
         session = HibernateUtil.getSessionFactory().getCurrentSession();
         session.beginTransaction();
         Category category = (Category)session.get(Category.class, postalCode);
         session.getTransaction().commit();
         return category;
      }
      catch(Exception e) {
         throw new Exception(e);
      }
      finally {
         HibernateUtil.closeSession(session);
      }
   }
}



And my hibernate.cfg.xml:

[/code]
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- MySQL -->

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/esg</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">asdf</property>

<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.formate_sql">false</property>


<!-- Mappings -->
<mapping class="de.waldhausweg7.model.Category" />
</session-factory>
</hibernate-configuration>
Code:

Can anybody help me,  please?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2008 1:11 pm 
Newbie

Joined: Thu Oct 18, 2007 10:38 am
Posts: 7
The same thing happened to me. It happened because I had the latest hibernate in my eclipse project and also the libs from the jboss. This is incompatible. Just use one of them and you should be fine.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 25, 2008 1:16 am 
Newbie

Joined: Wed Dec 24, 2008 2:21 am
Posts: 2
egore911 wrote:
The same thing happened to me. It happened because I had the latest hibernate in my eclipse project and also the libs from the jboss. This is incompatible. Just use one of them and you should be fine.


Excellent tip. Worked for me too.


Top
 Profile  
 
 Post subject: Re: Annotations: org.hibernate.AnnotationException
PostPosted: Sun May 10, 2009 3:20 pm 
Beginner
Beginner

Joined: Sat Oct 18, 2008 10:25 am
Posts: 30
Thank you very much. It worked.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.