Maven Hibernate Entity class not found Exception

Even if I know that this is one of the most common question, i could'nt solve it by myself so I decidet to ask it.

Hibernate can not find my .hbm.xml files or entity classes. This is my file structure:enter image description here

and this is one of the hbm files:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jul 24, 2015 9:36:20 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="org.kelime.dbModel.Kelime" table="kelime" catalog="distributedproject">
        <id name="kelime" type="string">
            <column name="Kelime" length="50" />
            <generator class="assigned" />
        </id>
    </class>
</hibernate-mapping>

and this is the error: org.hibernate.MappingNotFoundException: resource: org.kelime.dbModel.Kelime.hbm.xml not found at org.hibernate.cfg.Configuration.addResource(Configuration.java:724) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2102) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2074) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2054) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2007) at org.hibernate.cfg.Configuration.configure(Configuration.java:1922) at org.kelime.HibernateUtils.HibernateUtils.(HibernateUtils.java:15) at org.kelime.rest.AccountController.registerNewUser(AccountController.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source)

Upvotes: 0

Views: 702

Answers (2)

I and my friend have solved this problem.. I dont know why but for some reason it only works with this style of coding :

Configuration configuration = new Configuration(); configuration.addResource("./org/kelime/dbModel/Kelime.hbm.xml"); configuration.addResource("./org/kelime/dbModel/Kullanici.hbm.xml");

Upvotes: 0

bwright
bwright

Reputation: 936

You probably need to tell maven to include those files. Try something like this in your pom.xml:

<build>
    <resources>
        <resource>
            <directory>src/main/java/</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
</build>

Upvotes: 1

Related Questions