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?