Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 978941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:08:22+00:00 2026-05-16T04:08:22+00:00

I’ve been trying to get a simple skeleton app to run (and commit to

  • 0

I’ve been trying to get a simple skeleton app to run (and commit to the DB) using JPA, MySQL, Hibernate & Maven, however I’m having problems.

Listed below are my 2 trivial classes, my pom.xml, and my META-INF/persistence.xml

I can build the project without any problem (mvn clean install), however running it (mvn exec:java -Dexec.mainClass=com.foo.HelloWorld -X) causes an exception, with the following StackTrace.

Any help would be greatly appreciated!

Stacktrace:

org.apache.maven.lifecycle.LifecycleExecutionException: An exception occured while executing the Java class. null
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. null
        at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:346)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        ... 17 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:291)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoSuchMethodError: org.hibernate.event.PreInsertEvent.getSource()Lorg/hibernate/engine/SessionImplementor;
        at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:167)
        at org.hibernate.action.EntityIdentityInsertAction.preInsert(EntityIdentityInsertAction.java:142)
        at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:65)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
        at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
        at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
        at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
        at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
        at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
        at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:646)
        at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:620)
        at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:624)
        at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
        at com.foo.HelloWorld.create(HelloWorld.java:32)
        at com.foo.HelloWorld.main(HelloWorld.java:11)
        ... 6 more

I have the following two classes:
The Entity to store.

package com.foo;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Message {
    @Id
    @GeneratedValue
    private int id;
    @Basic
    private String message;

    public Message() {}

    public Message(String message) {
        this.message = message;
    }

    public String toString() {
        return "Greeting id=" + id + ", message=" + message;
    }
}

The Application:

package com.foo;

public class HelloWorld {
    private javax.persistence.EntityManagerFactory emf;
    private javax.persistence.EntityManager em;
    private String PERSISTENCE_UNIT_NAME = "hello-world";

    public static void main(String[] args) {
        HelloWorld hello = new HelloWorld();
        hello.initEntityManager();
        hello.create();
        //        hello.read();
        hello.closeEntityManager();
    }

    private void initEntityManager() {
        emf = javax.persistence.Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
        em = emf.createEntityManager();
    }

    private void closeEntityManager() {
        em.close();
        emf.close();
    }

    private void create() {
        em.getTransaction().begin();
        Message hello = new Message("hello world");
        Message bye = new Message("goodbye, world");
        Message[] messages = new Message[] {hello, bye};
        for (Message m : messages) {
            em.persist(m);
        }
        em.getTransaction().commit();
    }

    //    private void read() {
    //        Message m = (Message)em.createQuery("select m from Message m").getSingleResult();
    //        System.out.println("Query returned: " + m);
    //    }
}

The following is my pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

 <modelVersion>4.0.0</modelVersion>
 <groupId>com.treocht.hibernate.tutorial</groupId>
 <artifactId>hibernate-tutorial</artifactId>
 <version>1.0.0-SNAPSHOT</version>
 <name>First Hibernate Tutorial</name>


 <dependencies>

  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-core</artifactId>
   <version>3.3.2.GA</version>
   <type>jar</type>
   <scope>compile</scope>
  </dependency>
  <dependency>
   <groupId>javax.persistence</groupId>
   <artifactId>persistence-api</artifactId>
   <version>1.0</version>
   <type>jar</type>
   <scope>compile</scope>
  </dependency>

  <dependency>
   <groupId>commons-logging</groupId>
   <artifactId>commons-logging</artifactId>
   <version>1.0.4</version>
  </dependency>

  <dependency>
   <groupId>hsqldb</groupId>
   <artifactId>hsqldb</artifactId>
   <version>1.8.0.7</version>
  </dependency>

  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate</artifactId>
   <version>3.2.2.ga</version>
  </dependency>

  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-annotations</artifactId>
   <version>3.2.1.ga</version>
  </dependency>

  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-entitymanager</artifactId>
   <version>3.2.1.ga</version>
  </dependency>

  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-tools</artifactId>
   <version>3.2.0.beta9a</version>
  </dependency>

  <dependency>
   <groupId>c3p0</groupId>
   <artifactId>c3p0</artifactId>
   <version>0.9.1</version>
  </dependency>
  <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-api</artifactId>
   <version>1.6.1</version>
   <type>jar</type>
   <scope>compile</scope>
  </dependency>
  <dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
   <version>5.1.13</version>
   <type>jar</type>
   <scope>compile</scope>
  </dependency>
 </dependencies>

 <build>
  <!--
   we dont want the version to be part of the generated war file name
  -->
  <finalName>${artifactId}</finalName>

  <pluginManagement>
   <plugins>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <configuration>
      <source>1.6</source>
      <target>1.6</target>
     </configuration>
    </plugin>
   </plugins>
  </pluginManagement>
 </build>

</project>

And I have this META-INF/persistence.xml file:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd"
 version="1.0">

 <persistence-unit name="hello-world" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <class>com.foo.Message</class>
  <properties>
   <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/my_db" />
   <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
   <property name="hibernate.connection.password" value="password" />
   <property name="hibernate.connection.username" value="username" />
   <property name="hibernate.hbm2ddl.auto" value="update" />
  </properties>
 </persistence-unit>
</persistence>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:08:23+00:00Added an answer on May 16, 2026 at 4:08 am

    You’re indeed using incompatible versions of Hibernate artifacts as this can be verified using the official Hibernate Compatibility Matrix. Don’t rely on some random tutorial found around the net for that.

    But since you’re using Maven, you actually don’t need to declare all Hibernate artifacts, just leverage the transitive dependencies. So just declare a dependency in the hibernate-entitymanager (especially if you’re not sure of what you’re doing):

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>3.4.0.GA</version><!-- for JPA 1.0 -->
    </dependency>
    

    And remove these hibernate, hibernate-core, hibernate-annotations, persistence-api, slf4j dependencies.

    And if you want to change the version of the sfl4j-api artifact that you get transitively, you should do that in the dependency management section:

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.6.1</version>
        </dependency>
      </dependencies>
    </dependencyManagement>
    

    Actually (and I’m sorry to say so) your whole pom is a big mess, try to spend some time cleaning it. Use mvn dependency:tree (or some visual fronted offered by your IDE) to do so.

    And let me insist, don’t rely on some random (and wrong) tutorial found around the net, leverage Maven transitive dependency mechanism.

    PS: As of Hibernate 3.5, the various projects (Hibernate Annotation, Hibernate EntityManager) have been merged back to Hibernate Core and their versions are synchronized which simplifies a lot version management, even for Maven users.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.