I'm currently learning Hibernate and JPA and I just stumbled upon the following issue:
I have an entity class called User, and this class is annotated with the @Entity (JPA) annotation. My persistence.xml file does NOT have a mapping for it, yet I can use it on my EntityManager without issues.
I just created another entity, called Comment (some packages below), this one is also annotated with @Entity and is also NOT on my persistence.xml file. This one however, throws a org.hibernate.MappingException: Unknown entity exception when used on the EntityManager.
My persistence.xml file:
<?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="net.notfab.hibernatetest" transaction-type="RESOURCE_LOCAL">
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<!-- JPA Properties -->
<property name="javax.persistence.provider" value="org.hibernate.jpa.HibernatePersistenceProvider"/>
<property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url"
value="jdbc:mariadb://IP:PORT...."/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
<!-- Hibernate Properties -->
<property name="hibernate.connection.provider_class"
value="org.hibernate.hikaricp.internal.HikariCPConnectionProvider"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MariaDBDialect"/>
<property name="hibernate.connection.CharSet" value="utf8mb4_bin"/>
<property name="hibernate.connection.characterEncoding" value="utf8mb4_bin"/>
<property name="hibernate.connection.useUnicode" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.archive.autodetection" value="class, hbm" />
<!-- Hikari Properties -->
<property name="hibernate.hikari.minimumIdle" value="5"/>
<property name="hibernate.hikari.maximumPoolSize" value="10"/>
<property name="hibernate.hikari.idleTimeout" value="15000"/>
<property name="hibernate.hikari.leakDetectionThreshold" value="30000"/> <!-- 30 Seconds -->
<property name="hibernate.hikari.poolName" value="TestPool"/>
</properties>
</persistence-unit>
</persistence>
What may be causing this weird behavior?
Is there a way for me to continue using the annotated classes without having to declare them on the XML file? (It's 2018 already - Annotations are way better!).
Note: This question is similar but their end goal ended up being mapping on the XML, which I'm trying to avoid by all means. I'm also looking for an explanation to the above-mentioned behavior.
Edit: As requested by the comments, here is the full stacktrace https://hastebin.com/haguniheca.cs (as well as here https://hasteb.in/ipuzojoc.cs in case hastebin goes down again).
In this scenario, I'm not using Spring.
Edit 2: Here is my entity.
Edit 3: This is a gradle project, running off of a standalone (shaded) jar file on Java SE, currently using the following list of dependencies for persistence (among others):
compile group: 'org.hibernate', name: 'hibernate-hikaricp', version: '5.3.3.Final'
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.2.6'
Edit 4: As per Eugen's comment I did some testing and the cause of the issue seems to be IntelliJ. By running the shaded jar file on it's own from the command line, the issue is fixed. (Maybe the classpath is different when running off of the application debug?). The question then becomes "how can I fix IntelliJ's run configuration for my app?".