0

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>
1

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.