Deploying war from maven and hibernate
===

I am implementing a RESTFul Server using Jersey. I am using Maven to solve the dependencies, Hibernate to access the data base, getting the mapping through Annotations from the java classes, and Jetty as the applications server.

When I run my application in Eclipse (with mvn build ***jetty:run***), it works perfectly. However, when I create the war file and I run it over the jetty server (***java -jar dependency/jetty-runner.jar --port 8080 MyApp***), I get the following problem.


First, my HibernateUtil class looked like this:

    class HibernateUtil {
	private static final SessionFactory sessionFactory = buildSessionFactory();

	private static SessionFactory buildSessionFactory() {
		try {
			ServiceRegistry serviceRegistry;
			Configuration configuration = new Configuration();
			configuration.configure();
			serviceRegistry = new ServiceRegistryBuilder().applySettings(
                             configuration.getProperties()).buildServiceRegistry();
		    return configuration().buildSessionFactory(serviceRegistry);
		 	} catch (Throwable ex) {
			logger.error("Initial SessionFactory creation failed.", ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	
	protected static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
    }


And I was getting this exception:

    org.hibernate.MappingException: An AnnotationConfiguration instance is required
    to use <mapping class="paquete.Clase"/>
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1597)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1552)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1531)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1505)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
    at org.claritycentre.persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:29)
    at org.claritycentre.persistence.HibernateUtil.<clinit>(HibernateUtil.java:17)

And then I tried this: http://www.mkyong.com/hibernate/hibernate-error-an-annotationconfiguration-instance-is-required-to-use/
So my buildSessionFactory method became this:

    private static SessionFactory buildSessionFactory() {
         try {
			return new AnnotationConfiguration().configure().buildSessionFactory();
		 	} catch (Throwable ex) {
			logger.error("Initial SessionFactory creation failed.", ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

But I still got the same exception.
I have tried different solutions I found in the Internet, but nothing seems to work.

And I just do not understand why this exception only happens when I deploy the application from the war on the server and it does not happen when I run it from Eclipse.

Thanks in advance.