Olá pessoal, estou começando com o hibernate e preciso de uma ajuda,
Tenho um bean, uma DAO, a persistência, o log4j.properties como acredito que deva ser.
Quando executo, olha só o que acontece,
[code]16 [main]
INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.3.1.GA
31 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.2.5
31 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
31 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : cglib
31 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
93 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.3.2.GA
575 [main] ERROR org.hibernate.ejb.packaging.PersistenceXmlLoader - Error parsing XML: XML InputStream(5) O tipo de elemento meta" deve ser encerrado pela tag final correspondente “”.
Exception in thread “main” javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at example.DAO.RubricaReceitaDAO.insereRR(RubricaReceitaDAO.java:19)
at example.Main.Main.main(Main.java:19)
Caused by: org.xml.sax.SAXParseException; systemId: http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd; lineNumber: 5; columnNumber: 3; O tipo de elemento meta" deve ser encerrado pela tag final correspondente “”.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:254)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:70)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:89)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:222)
… 5 more
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 5 segundos)
[/code]
Obrigado
Existe algum erro no seu arquivo hibernate.cfg.xml
Verifique se todas tags estão fechadas
Acho que seu persistence.xml está mal formado, poste ele aí
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="SIFIUNPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>example.entities.RubricaReceita</class>
<properties>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="---"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/financeiro"/>
</properties>
</persistence-unit>
</persistence>
Tenho procurado bastante sobre, mas não achei muita coisa, então estou tentando aprender de forma mais experimental, hehe.
Me desculpem se for muita noobice !
o xml parece correto…
poste o método insereRR da classe RubricaReceitaDAO
public void insereRR(RubricaReceita rr){
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SIFIUNPU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(rr);
em.getTransaction().commit();
em.close();
emf.close();
}
Resolvido, era a persistence mesmo
<persistence>
<persistence-unit name="SIFIUNPU" transaction-type="RESOURCE_LOCAL">
<class>example.entities.RubricaReceita</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="---"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/financeiro"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="false" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.jdbc.batch_size" value="50" />
<!-- alternatively to <class> and <property> declarations, you can use a regular hibernate.cfg.xml file -->
<!-- property name="hibernate.ejb.cfgfile" value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
</properties>
</persistence-unit>
</persistence>
Obrigado pela atenção
Só achei interessante é que agora toda vez que eu executo um insere, ele zera o conteúdo da minha tabela.
Resolvido também, é só alterar o create para update na linha
<property name="hibernate.hbm2ddl.auto" value="create" />
Haha, tinha encontrado isso em outro tópico, noobice minha perguntar em pesquisar, mas obrigado mesmo assim !