I am new to Java Hibernate. I setup a dynamic web project in eclipse and trying to insert a row in mysql db. I am getting the following error when I run my code on server.
java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/ClassLoaderDelegate
org.hibernate.boot.internal.MetadataBuilderImpl.(MetadataBuilderImpl.java:127)
org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:135)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:655)
My hibernate.cfg.xml
<session-factory>
<!-- Database connection settings -->
<property name='connection.driver_class'>com.mysql.jdbc.Driver</property>
<property name='connection.url'>jdbc:mysql://localhost:3306/bornscientific</property>
<property name='connection.username'>root</property>
<property name='connection.password'></property>
<!-- JDBC connection pool (use the built-in) -->
<property name='connection.pool_size'>1</property>
<!-- SQL dialect -->
<property name='dialect'>org.hibernate.dialect.MySQLDialect</property>
<!-- Echo all executed SQL to stdout -->
<property name='show_sql'>true</property>
<!-- Mapping files -->
<mapping class="com.bornscientific.persistence.beans.Tags"/>
</session-factory>
My entity class
package com.bornscientific.persistence.beans;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
#Entity
#Table(name = "TAGS")
public class Tags implements Serializable
{
private Long id;
private String name;
public Tags()
{
}
#Id
#SequenceGenerator(name="seq1",sequenceName="HIB_SEQ")
#GeneratedValue(strategy=GenerationType.SEQUENCE,generator="seq1")
#Column(name = "TAG_ID", unique = true, nullable = false)
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
#Column(name = "NAME", unique = true, length = 100, nullable = false)
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
And my main method is
public static void test() throws Exception
{
try
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.getTransaction();
tx.begin();
Tags tags = new Tags();
tags.setName("TAG_1");
session.save(tags);
tx.commit();
System.out.println("Saved successfully...");
}
catch(Exception e)
{
//System.out.println(e)
e.printStackTrace();
}
}
HibernateUtil.java
package com.bornscientific.persistence;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class HibernateUtil
{
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory()
{
try
{
Configuration configuration = new Configuration().configure();
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
serviceRegistryBuilder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
return configuration.buildSessionFactory(serviceRegistry);
}
catch (Throwable ex)
{
System.err.println("Initial SessionFactory creation failed." + ex);
ex.printStackTrace();
throw ex;
}
}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}
}
And this is the library referenced.
Please help me fix this issue. I have searched through google and could not find a solution.
Related
I have a question about my hibernate mapping, I am creating a project with Spring and hibernate, I am facing a issue that I can solve it so far and I couldn't find someone able to help me so far, so I mapped the database and did everything as expected but I am receiving this message:
HHH000183: no persistent classes found for query class: FROM com.inbox.model.Estado
My hibernate.cfg.xml is like this
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://inboxmysqldb.c4lcntgo83fr.us-west-2.rds.amazonaws.com</property>
<property name="hibernate.connection.username">inboxuser</property>
<property name="hibernate.connection.password">xxxxxx</property>
<!-- <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property> -->
<property name="hibernate.show_sql">false</property>
<!-- <property name="hibernate.hbm2ddl.auto">true</property>-->
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Mapping files -->
<!-- <mapping class="com.inbox.model.Box"/> -->
<mapping class="com.inbox.model.Estado"/>
</session-factory>
</hibernate-configuration>
My class is mapped like this:
package com.inbox.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
#Entity(name="com.inbox.model.Estado")
#Table(name = "estado",
uniqueConstraints={#UniqueConstraint(columnNames={"id"})})
public class Estado implements IdentifierInterface, Serializable{
/**
*
*/
private static final long serialVersionUID = 3625863483844458267L;
#Id
#GeneratedValue(strategy = javax.persistence.GenerationType.IDENTITY)
#Column(name="id", nullable=false, unique=true, length=11)
private Integer id;
#Column(name="nome", length=20, nullable=true)
private String nome;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}
HibernateUtil:
public class HibernateUtil {
private static SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
if (sessionFactory == null) {
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
return sessionFactory;
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static Session getSession() {
return getSessionFactory().openSession();
}
}
As requested follow the query
public T findById(int id) {
Session session = HibernateUtil.getSession();
session.beginTransaction();
try {
Query byIdQuery = session.createQuery("FROM " + entityClassName + " as c WHERE c.id = :id");
byIdQuery.setParameter("id", id);
return (T) byIdQuery.uniqueResult();
} catch (Exception e) {
throw new InboxException(e);
} finally {
session.close();
}
}
I ran out of ideas to try fix.
Thanks in advance
I'm trying to create a small project with hibernate, but i got that error "Type is not mapped [select o from Type o]", I added mapping in hibernate.cfg.xml but still error.
Type.java:
package com.formation.gestionprojet.doa.entity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name="Type")
public class Type implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
#Id
private Long id;
private String name;
private String description;
private String active;
public Type() {
super();
// TODO Auto-generated constructor stub
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getActive() {
return active;
}
public void setActive(String active) {
this.active = active;
}
}
hibernate.org.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- database connection setting -->
<property name ="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/gestion_projet?createDatabaseIfNotExist=true</property>
<property name="connection.username">root</property>
<property name= "connection.password">root</property>
<!-- Dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Disable the second level cache -->
<property name="cache.provider_class" >org.hibernate.cache.NoCacheProvider</property>
<!-- echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drope and re-create the database -->
<property name="hbm2ddl.auto">update</property>
<!-- mapping -->
<mapping class= "com.formation.gestionprojet.doa.entity.Type"/>
</session-factory>
</hibernate-configuration>
hibernateUtil.java:
package com.formation.gestionprojet.utils;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
#SuppressWarnings("deprecation")
public class HibernateUtil
{
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;
static
{
try
{
Configuration configuration = new Configuration();
configuration.configure("config/hibernate.cfg.xml");
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
catch (HibernateException ex)
{
System.err.println("Error creating Session: " + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}
public static Session openSession()
{
return sessionFactory.openSession();
}
public static Session getCurrentSession()
{
return sessionFactory.getCurrentSession();
}
public static void close(){
if(sessionFactory!=null){
sessionFactory.close();
}
}
}
Test.Java
package com.formation.gestionprojet.utils;
import org.hibernate.Session;
public class Test {
static Session session = HibernateUtil.openSession();
public static void main(String[] args) {
session.createQuery("select o from Type o").list();
}
}
solved ! the problem was the version of hibernate that I used so I change it, a change in HibernateUtil.
I am new to hibernate. i am following a tutorial and trying to execute a simple code but I am getting below error.
org.hibernate.MappingException: Unknown entity:
I am using annotations and configuration file also did exactly according the tutorials. I have googled but didn't get the correct answer
This is my code
package org.anne;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
public class Demo {
public static void main(String[] args) {
Paper p = new Paper();
p.setPname("indu");
SessionFactory sf = HibernateUtil.getSessionFactory();
Session ses = sf.openSession();
Transaction tr = ses.beginTransaction();
ses.save(p);
tr.commit();
ses.close();
sf.close();
}
}
package org.anne;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
static SessionFactory sf;
public static SessionFactory getSessionFactory()
{
Configuration cf = new Configuration();
cf.configure("hibernate.cfg.xml");
StandardServiceRegistryBuilder srv = new StandardServiceRegistryBuilder();
StandardServiceRegistry sr = srv.applySettings(cf.getProperties()).build();
sf = cf.buildSessionFactory(sr);
return sf;
}
}
package org.anne;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "PAPER")
public class Paper {
int pid;
String pname;
#Id
#Column(name = "PID")
#GeneratedValue(strategy = GenerationType.AUTO)
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
#Column(name = "PNAME")
public String getPname() {
return pname;
}
public void setPname(String pname) {
this.pname = pname;
}
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<property name = "connection.driver_class">com.mysql.jdbc.Driver</property>
<property name = "connection.url">jdbc:mysql://localhost:3306/test</property>
<property name = "connection.username">root</property>
<property name = "connection.password">abc123</property>
<property name = "hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name = "hibernate.show_sql">true</property>
<mapping class = "org.anne.Paper" />
</session-factory>
</hibernate-configuration>
If you boot Hibernate yourself, make sure to use the AnnotationConfiguration class instead of the Configuration class. Here is an example using the (legacy) HibernateUtil approach:
package hello;
import org.hibernate.*;
import org.hibernate.cfg.*;
import test.*;
import test.animals.Dog;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new AnnotationConfiguration()
.configure().buildSessionFactory();
} catch (Throwable ex) {
// Log exception!
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession()
throws HibernateException {
return sessionFactory.openSession();
}
}
More here https://docs.jboss.org/hibernate/stable/annotations/reference/en/html/ch01.html#setup-configuration
I am trying to add Hibernate 5 as ORM for a backend to connect with a MySQL-database. I read many examples and tutorials but I always get an InvocationTargetException.
Here are the relevant code. Hope someone can help me.
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/cooking</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="de.fani.cooking.object.User"/>
</session-factory>
</hibernate-configuration>
HibernateUtil.java
package de.fani.cooking.hibernate;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class HibernateUtil
{
private static SessionFactory sessionFactory;
private static SessionFactory buildSessionFactory()
{
try
{
// Create session factory from cfg.xml
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}
catch (Throwable ex)
{
System.err.println("Initial session factory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory()
{
if (sessionFactory == null)
{
sessionFactory = buildSessionFactory();
}
return sessionFactory;
}
}
User.java
package de.fani.cooking.object;
import javax.persistence.*;
#Entity (name = "User")
#Table(name="User", uniqueConstraints={#UniqueConstraint(columnNames = {"id"})})
public class User
{
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column (name = "id", nullable = false, unique = true, length = 11)
private int id;
#Column (name = "username", nullable = false, length = 30)
private String username;
#Column (name = "password", nullable = false, length = 256)
private String password;
public int getId() {
return id;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public void setId(int id) {
this.id = id;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public User()
{
}
}
SQL
CREATE TABLE `User` (
`id` int(11) NOT NULL,
`username` varchar(30) NOT NULL,
`password` varchar(256) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
UserResource.java
package de.fani.cooking.resource;
import de.fani.cooking.hibernate.HibernateUtil;
import de.fani.cooking.object.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
#Path("/user")
public class UserResource
{
#POST
#Path("register")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public Response register(User _user)
{
User test = new User();
test.setId(24);
test.setUsername("tester");
test.setPassword("secret");
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
sessionFactory.openSession();
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
session.save(test);
session.getTransaction().commit();
session.flush();
return Response.status(Response.Status.OK).entity(_user).build();
}
}
Exception at session.save(test);:
SCHWERWIEGEND: Servlet.service() for servlet [ApplicationConfig] in context with path [] threw exception [org.hibernate.MappingException: Unknown entity: de.fani.cooking.object.User] with root cause
org.hibernate.MappingException: Unknown entity: de.fani.cooking.object.User
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:776)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1462)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:100)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:678)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:670)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:665)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:338)
at com.sun.proxy.$Proxy58.save(Unknown Source)
Thanks a lot!
Ok, I found the answer by myself. The problem was the way I initialized the configuration, if I understand it correctly.
I changed it to:
private static SessionFactory buildSessionFactory()
{
try
{
// Create session factory from cfg.xml
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.configure("hibernate.cfg.xml")
.build();
Metadata Meta = new MetadataSources(serviceRegistry)
.addAnnotatedClass(User.class)
.addAnnotatedClassName("de.fani.cooking.model.User")
.getMetadataBuilder()
.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE)
.build();
SessionFactory sessionFactory = Meta.getSessionFactoryBuilder()
.build();
return sessionFactory;
}
catch (Throwable ex)
{
System.err.println("Initial session factory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
And now it works! :-)
I have a problem trying to create a query from a Struts2 application with Hibernate and DB2 database. It throws me an Exception:
Struts Problem Report
Struts has detected an unhandled exception:
Messages:
ClienteCRM is not mapped
ClienteCRM is not mapped [FROM ClienteCRM WHERE nombre LIKE XXXX]
File: org/hibernate/hql/internal/ast/util/SessionFactoryHelper.java
Line number: 171
First of all this is my project tree:
I have this files:
Hibernate configuration file:
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="hibernate.connection.driver_class">com.ibm.as400.access.AS400JDBCDriver</property>
<property name="hibernate.connection.url">jdbc:as400://10.10.10.131/sugarcrmak </property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">pwd</property>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<mapping class="com.ak.exchange.model.dto.ClienteCRM" />
</session-factory>
Bean
package com.ak.exchange.model.dto;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name="accounts")
//#NamedQuery(name="ClienteCRM.buscarPorNombre", query="from ClienteCRM c where c.nombre like :nombre")
public class ClienteCRM implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
#Id
#Column(name="id")
private String id;
#Column(name="name")
private String nombre;
public ClienteCRM(){
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
}
DAO layer for ClienteCRM
package com.ak.exchange.model.dao;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.ak.exchange.model.dto.ClienteCRM;
public class ClienteDAO {
protected Session session;
protected void openSession(){
Configuration configuration = new Configuration().configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
session = sessionFactory.openSession();
}
protected void closeSession(){
session.close();
}
public List<ClienteCRM> buscarClientesCRMPorNombre (String aNombre){
this.openSession();
session.beginTransaction();
// Query query = session.getNamedQuery("ClienteCRM.buscarPorNombre");
// query.setParameter("nombre", "%" + aNombre + "%");
Query selectAll = session.createQuery("FROM ClienteCRM WHERE nombre LIKE " + aNombre);
#SuppressWarnings("unchecked")
List<ClienteCRM> tmpClientes = (List<ClienteCRM>) selectAll.list();
this.closeSession();
return tmpClientes;
}
}
As you can see, I've tried to create a query by using a NamedQuery (commented) and also creating from the DAO.
Any idea?
Thanks a lot
Put your hibernate.cfg.xml inside src/main/resources
Put your mapping files inside src/main/resources
Map your files like this:
<mapping resource="ClienteCRM.hbm.xml" />
It should work.