Boa tarde galera, estou aprendendo JPA estudando pela apostila da K-19, no começo da apostila tem um exercicio pratico em que criamos uma classe editora, um arquivo xml de configuração do hibernate e uma classe geraTabelas, segui tudo direitinho na apostila, porém qd executo o geraTabelas, dar um erro, esse:
Ago 11, 2013 11:32:39 AM org.hibernate.annotations.common.Version
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Ago 11, 2013 11:32:39 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.3.Final}
Ago 11, 2013 11:32:39 AM org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
Ago 11, 2013 11:32:39 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
[Fatal Error] :7:3: Element type “persistence” must be followed by either attribute specifications, “>” or “/>”.
Exception in thread “main” javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML (line7 : column 3): Element type “persistence” must be followed by either attribute specifications, “>” or “/>”.
Irei psotar meu codigo a seguir:
Classe Editora:
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Editora implements Serializable {
@Id @GeneratedValue
private Long id;
private String nome;
private String email;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
Arquivo persistence.xml
<?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"
<persistence-unit name="livraria" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.hbm2dd1.auto" value="create"/>
<property name="javax.persistence.jdbc.driver"
value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user"
value="root"/>
<property name="javax.persistence.jdbc.password"
value="!Cearamor88"/>
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/livraria"/>
</properties>
</persistence-unit>
</persistence>
classe geraTabelas
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class GeraTabelas {
public static void main(String[] args) {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("livraria");
factory.close();
}
}
Agradeço desde já!