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

  • Home
  • SEARCH
  • 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 8532575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:44:48+00:00 2026-06-11T09:44:48+00:00

I would like to implement a program in Java able to interact with a

  • 0

I would like to implement a program in Java able to interact with a database. I have already done something like this using EJB, but this time I need it to be able to work without an application server. What I have done so far is (with Eclipse):

  • Create a db connection
  • Create a JPA project
  • Create entities (correctly mapped)
  • Set persistence.xml (it is in META-INF folder)
  • Import MySQL JDBC Driver library and persistence-api-1.0.2.jar

Here is my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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 http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="top" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>database.Match</class>
        <class>database.Player</class>
        <class>database.Tournament</class>
        <properties>
            <property name="hibernate.connection.provider_class" value="org.hibernate.connection.DriverManagerConnectionProvider"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/top"/>
            <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value="root"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>
    </persistence-unit>
</persistence>

Here is how I try to use an EntityManager:

private static EntityManagerFactory factory;
private EntityManager entityManager;

public DBManager() {
    factory = Persistence.createEntityManagerFactory("top");
    entityManager = factory.createEntityManager();
}

public Player createPlayer(String name, int age, Court favouriteCourt, int currentRanking) {
    Player player = new Player();
    player.setAge(age);
    player.setCurrentRanking(currentRanking);
    player.setFavouriteCourt(favouriteCourt);
    player.setName(name);
    entityManager.persist(player);
    return player;
}

My Main class just simply creates a new DBManager and tries to use createPlayer.

I get the following exception:

    Exception in thread "main" javax.persistence.PersistenceException: No resource files named META-INF/services/javax.persistence.spi.PersistenceProvider were found. Please make sure that the persistence provider jar file is in your classpath.
    at javax.persistence.Persistence.findAllProviders(Persistence.java:167)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:103)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at database.DBManager.<init>(DBManager.java:17)
    at database.Main.main(Main.java:8)

Adding hibernate-entitymanager-3.3.2.GA.jar I get:

    Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named top: Provider named org.hibernate.ejb.HibernatePersistence threw unexpected exception at create EntityManagerFactory: 
java.lang.NoClassDefFoundError
java.lang.NoClassDefFoundError: org/hibernate/MappingException
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:124)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at database.DBManager.<init>(DBManager.java:17)
    at database.Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: org.hibernate.MappingException
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more



    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at database.DBManager.<init>(DBManager.java:17)
    at database.Main.main(Main.java:8)

What am I missing? Do I need to import other jars? Or to set something else in the descriptor?

  • 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-06-11T09:44:49+00:00Added an answer on June 11, 2026 at 9:44 am

    What you’re missing is that hibernate-entitymanager just contains the wrapper that wraps hibernate core to expose it as a JPA entity manager. So if you’ve only added that you won’t get the actual hibernate classes, hence your class not found.

    If you look at the picture of how the components tie together on the hibernate home page you’ll see that entity manager builds on hibernate core and hibernate annotations. You’ll need to add the required jars for both of these as well as all their dependencies.

    The docs describe the various folders of jars in the hibernate distro and exactly which sets of jars you need for what kind of usage.

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

Sidebar

Related Questions

I have a problem with Java. I would like to write a program where
I have a problem with Java. I would like to write a program where
I have 3 tab items to implement. When the program executes, I would like
I would like to implement a command line interface for a Java application. This
I would like to implement a simple AR desktop application. This application should first
I would like to implement something similar to 37Signals's Yellow Fade effect. I am
I would like to implement a map simmilar to this: http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/examples/advanced_example.html One of the
I would like to convert my Simple Java program to an Applet Program. I've
I have built a little daemon in Java and I would like to run
I would like to implement a distinct thread for each route in apache camel.I

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.