Ola pessoal estou estudando uma apostila da k-19, so que eu estou usando o netbeans e nao o eclipse como a apostila.
Pois bem criei um novo projeto web, adicionei manualmente as bibliotecas hibernate e log4,
Crie uma unidade de persistencia o persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">
<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.hbm2ddl.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="vertrigo"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/livraria1"/>
</properties>
</persistence-unit>
</persistence>
criei o log4j.proprerties
log4j.rootCategory=INFO, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%r [%t] %-5p %c - %m%n
e criei uma classe que ira persistir no banco
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package modelo;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
*
* @author Fred
*/
@Entity
public class Editora {
@Id @GeneratedValue
private Long id;
private String nome;
private String email;
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the nome
*/
public String getNome() {
return nome;
}
/**
* @param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
}
Fiz uma classe pra gerar as tabelas
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package modelo;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
*
* @author Fred
*/
public class GeraTabelas {
public static void main (String[] args) {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("Livraria1");
factory.close();
}
}
ao executar esta classe da o sequinte erro:
131228 [main] ERROR org.hibernate.ejb.packaging.PersistenceXmlLoader - Error parsing XML: XML InputStream(5) The entity name must immediately follow the '&' in the entity reference.
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 modelo.GeraTabelas.main(GeraTabelas.java:18)
Caused by: org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
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)
... 4 more
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 2 minutos 13 segundos)
Alguem sabe que erro é este?
Obrigado