Problema com JPA

1 resposta
ThiagoWorldCoder

Boa tarde pessoal, eu estou fazendo o exemplo de uma aplicação simples com JPA, o meu arquivo persistence.xml está na pasta META-INF, e a pasta META-INF está na pasta do projeto.
Acontece que eu gostaria de colocar está pasta aonde eu quizesse, por exemplo, dentro de uma pasta etc, só que quando eu faço isso e executo, dá um erro. O problema não é nem o erro, o erro fala que não encontra o dialeto correto, mas na verdade acontece que está parecendo que ele não encontra é o arquivo persistence.xml, por ele estar em uma outra pasta. vejam a estrutura do meu projeto:

etc
META-INF
persistence.xml
lib
src
hello
HelloWorld.java
Message.java
log4j.properties

Esse aqui é o meu persistence.xml

<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="helloworld">

       <!-- The provider only needs to be set if you use several JPA providers
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
        -->
       <!-- This is required to be spec compliant, Hibernate however supports
            auto-detection even in JSE.
       <class>hello.Message</class>
        -->

      <properties>
          <!-- Scan for annotated classes and Hibernate mapping XML files -->
          <property name="hibernate.archive.autodetection" value="class, hbm"/>

          <!-- SQL stdout logging
          <property name="hibernate.show_sql" value="true"/>
          <property name="hibernate.format_sql" value="true"/>
          <property name="use_sql_comments" value="true"/>
          -->

          <property name="hibernate.connection.driver_class"
                    value="com.mysql.jdbc.Driver"/>
          <property name="hibernate.connection.url"
                    value="jdbc:mysql://localhost/testes"/>
          <property name="hibernate.connection.username"
                    value="root"/>
	 	  <property name="hibernate.connection.password"
                    value="admin"/>

          <property name="hibernate.c3p0.min_size"
                    value="5"/>
          <property name="hibernate.c3p0.max_size"
                    value="20"/>
          <property name="hibernate.c3p0.timeout"
                    value="300"/>
          <property name="hibernate.c3p0.max_statements"
                    value="50"/>
          <property name="hibernate.c3p0.idle_test_period"
                    value="3000"/>

          <property name="hibernate.dialect"
                    value="org.hibernate.dialect.MySQLDialect"/>

      </properties>
   </persistence-unit>

</persistence>

E esse aqui é o meu Hello World

EntityManagerFactory emf =
                Persistence.createEntityManagerFactory("helloworld");

        // First unit of work
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();

        Message message = new Message("Hello World with JPA");
        em.persist(message);

        tx.commit();
        em.close();
        emf.close();

Aonde e o que eu tenho que alterar para poder colocar o persistence.xml com a pasta META-INF em outro lugar?

Grato pela atenção!!!

1 Resposta

rafaelglauber

2.2. Configuration and bootstrapping
2.2.1. Packaging

The configuration for entity managers both inside an application server and in a standalone application reside in a persistence archive. A persistence archive is a JAR file which must define a persistence.xml file that resides in the META-INF folder. All properly annotated classes included in the archive (ie having an @Entity annotation), all annotated packages and all Hibernate hbm.xml files included in the archive will be added to…

retirado daqui.

Criado 27 de dezembro de 2007
Ultima resposta 27 de dez. de 2007
Respostas 1
Participantes 2