Reputation: 2322
I've i run into an exeption while trying to use Hibernate 4.3.x with java on netbeans, the exption is:
Exception in thread "main" java.lang.ExceptionInInitializerError
at teste.ConectaJavaDB.main(ConectaJavaDB.java:17)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource model/Equipe.hbm.xml
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3764)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3753)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3741)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at conexao.HibernateUtil.buildSessionFactory(HibernateUtil.java:25)
at conexao.HibernateUtil.<clinit>(HibernateUtil.java:14)
... 1 more
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping model.Equipe
at org.hibernate.cfg.Configuration$MappingsImpl.addClass(Configuration.java:2837)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:178)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3761)
... 7 more
(the second error says about duplicate mapping, but i dindt mapped twice) by reading the exeption, it's possible to see that the problem is in the mapping xml of the class Equipe, the XML contains:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="model">
<class name="model.Equipe" table="equipe">
<id name="id" type="int" column="ID" >
<generator class="increment"/>
</id>
<property name="nome"/>
<property name="dataNascimento"/>
<property name="email"/>
<property name="enderecoWeb"/>
<property name="fone"/>
</class>
</hibernate-mapping>
And the class:
package model;
import java.util.Date;
public class Equipe {
private int id;
private String nome;
private Date dataNascimento;
private String email;
private String enderecoWeb;
private String fone;
[..]getters and setters[..]
Hibernate.cgf
<?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.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">app</property>
<property name="hibernate.connection.password">app</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="model.Jogador"/>
<mapping resource="model/Equipe.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I can't seem to find the error, the hole code is posted on Bitbucket above, thanks!
Hole code: https://bitbucket.org/angelorodem/progapl_ii_272278_2015/src
Upvotes: 0
Views: 612
Reputation: 5502
You invoked configuration.configure()
twice. Remove the second invocation, or just copy paste the code below:
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
Upvotes: 1
Reputation: 322
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="model.Jogador"/> (remove this)
<mapping resource="model/Equipe.hbm.xml"/>
try this:
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="model/Equipe.hbm.xml"/>
Upvotes: 0