P
P
ProtCN2020-10-20 13:52:25
Java
ProtCN, 2020-10-20 13:52:25

How to fix PersistenceException: Unable to resolve persistence unit root URL?

Man, please help me with this nasty problem!
Uses Spring-Framework (not boot or web) and an annotated JavaConfig for beans and JPA configuration.

I don't know why, but when I run the application, I get an exception from the title of the question.
The project tree does not contain any xml content (orm.xml, persistence.xml, etc.), since it seems to be unnecessary.

Help get rid of this binary splinter!

JpaConfiguration.class

@Configuration
public class JpaConfiguration {

    @Bean
    public DataSource dataSource() {
        SQLBaseAuth auth = getAuth();
        MysqlDataSource dataSource = new MysqlDataSource();
        dataSource.setUrl(auth.getUrl());
        dataSource.setUser(auth.getUser());
        dataSource.setPassword(auth.getPassword());
        return dataSource;
    }

    @Bean
    public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
        return new JpaTransactionManager(emf);
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
        em.setDataSource(dataSource());
        em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
        em.setPackagesToScan("com.myrepo.scan_packages");
        return em;
    }
}


pom.xml
<dependencies>

        <!-- MYSQL/JDBC -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>

        <!-- SPRING-CONTEXT -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring-framework.version}</version>
        </dependency>

        <!-- SPRING-JPA -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${spring-jpa.version}.RELEASE</version>
        </dependency>

        <!-- HIBERNATE-CORE -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.22.Final</version>
        </dependency>

        <!-- JAVAX-PERSISTENCE-API -->
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>${javax.persistence.version}</version>
        </dependency>

    </dependencies>


*logs*
[17:56:52] [Server thread/INFO]: Bean 'jpaConfiguration' of type [ru.prisonlife.spring.JpaConfiguration$$EnhancerBySpringCGLIB$$379496b4] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[17:56:53] [Server thread/WARN]: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.myrepo.spring.JpaConfiguration: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
[17:56:53] [Server thread/ERROR]: Error occurred while enabling PLCore v1.0.0 (Is it up to date?)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.myrepo.spring.JpaConfiguration: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) ~[?:?]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[?:?]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[?:?]
  at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[?:?]
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[?:?]
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[?:?]
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[?:?]
  at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[?:?]
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[?:?]
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[?:?]
  at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:89) ~[?:?]
  at com.myrepo.Main.launchSpring(Main.java:253) ~[?:?]
  at com.myrepo.Main.onEnable(Main.java:60) ~[?:?]
  at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
  at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:352) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
  at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
  at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:462) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
  at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:376) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
  at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:457) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
  at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:267) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
  at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:784) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
  at java.lang.Thread.run(Thread.java:748) [?:1.8.0_261]
Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
  at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:641) ~[?:?]
  at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:463) ~[?:?]
  at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:444) ~[?:?]
  at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:328) ~[?:?]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[?:?]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ~[?:?]
  ... 21 more
Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist
  at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195) ~[?:?]
  at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:637) ~[?:?]
  at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:463) ~[?:?]
  at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:444) ~[?:?]
  at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:328) ~[?:?]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[?:?]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ~[?:?]
  ... 21 more
[17:56:53] [Server thread/INFO]: [Holograms] Enabling Holograms v2.12
[17:56:53] [Server thread/INFO]: [Holograms] HologramEntityController set to: com.sainttx.holograms.nms.v1_15_R1.HologramEntityControllerImpl
[17:56:53] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
[17:56:53] [Server thread/INFO]: Done (13.387s)! For help, type "help"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question