Spasitel
Spasitel

Reputation: 169

Hibernate Mapping Exception, working with annotations

I'm trying to work with Hibernate and MySQL. I created some test instances and tried to save them, but ran into an

hibernate.MappingException: Unknown entity: ....Category.

The Category class looks as follows:

import javax.persistence.*;
import java.util.Set;

@Entity
@Table(name = "categories_table")
public class Category {

    @Id
    @Column
    private String code;
    @Column
    private String name;
    @OneToMany(mappedBy = "category")
    private Set<Addon> addons;

the hibernate.cfg.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost/xa04?createDatabaseIfNotExist=true</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.connection.password">password</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hibernate.hbm2ddl.auto">update</property>
 </session-factory>
</hibernate-configuration>

Upvotes: 0

Views: 63

Answers (1)

Maciej Kowalski
Maciej Kowalski

Reputation: 26522

You need to update your config with appropriate mapping(s) containing fully-qualified class names or wildacrds:

<hibernate-configuration>
 <session-factory>
  ...
  <mapping class="com.mypackage.Category" />
 </session-factory>
</hibernate-configuration>

Upvotes: 2

Related Questions