0

My test class:

package com.example.permissions.impl;

import lombok.Data;

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

@Table
@Data
@Entity
public class TestEnt {
    @Id
    @GeneratedValue
    private long id;

    private String testStr;
}

My persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd ">
    <persistence-unit name="persistence" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <shared-cache-mode>ALL</shared-cache-mode>
        <validation-mode>AUTO</validation-mode>

        <properties>
            <property name="hibernate.archive.autodetection" value="class, hbm"/>

            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/data" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="qwerty" />
            <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" />

            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL57Dialect" />
            <property name="hibernate.hbm2ddl.auto" value="validate" />

            <!-- Configuring Connection Pool -->
            <property name="hibernate.c3p0.min_size" value="5" />
            <property name="hibernate.c3p0.max_size" value="20" />
            <property name="hibernate.c3p0.timeout" value="500" />
            <property name="hibernate.c3p0.max_statements" value="50" />
            <property name="hibernate.c3p0.idle_test_period" value="2000" />
        </properties>
    </persistence-unit>
</persistence>

I have multi-module project. Main module loads data-manager with hibernate and other submodules.

I'm using hibernate-core:5.2.10.Final and hibernate-c3p0:5.2.10.Final with mysql connector v6.0.6

I can't persist my TestEnt with EntityManager.

    EntityManager em = PersistenceManager.getEntityManager();
    em.getTransaction().begin();
    em.persist(ent);
    em.getTransaction().commit();

I'm getting this exception: java.lang.IllegalArgumentException: Unknown entity: permissions.impl.TestEnt

I tried to add class node with com.example.permissions.impl.TestEnt in my persistence.xml - same exception.

PersisteceManager, if need:

package com.example.data.api;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class PersistenceManager {

    private static EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("persistence");

    public static EntityManager getEntityManager() {
        return emFactory.createEntityManager();
    }

    public static void close() {
        emFactory.close();
    }
}

UPD: Okay. According this: docs - i need persistence archive.(jar with persistence.xml for models). Let's try!

UPD2: Nope. Same exception(i just copied persistence.xml and added class node.

trusteduser
  • 29
  • 1
  • 4

0 Answers0