Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

PersistenceContext = Cannot parse persistence unit from class path resource [META-INF/persistence.xml]

Estou tentando deixar o Spring tomar conta das transações pelo entityManagerFactory, temos spring-context configurado, persistence.xml na pasta META-INF do class path. o fato é que um erro ocorre PersistenceContext = Cannot parse persistence unit from class path resource [META-INF/persistence.xml]

Se alguém puder me ajudar agradeço

Spring Context

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                        http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context 
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="br.com.solution" />
    <mvc:annotation-driven />
    <mvc:default-servlet-handler />

    <bean id="mysqlDataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
        <property name="url" value="jdbc:hsqldb:mem:." />
        <property name="username" value="sa" />
        <property name="password" value="" />
    </bean>


    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="mysqlDataSource" />
        <property name="persistenceUnitName" value="punit"/>
    <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
        <property name="jpaVendorAdapter">

            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>


    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

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_2_0.xsd"
    version="2.0">

 <persistence-unit name="punit" transaction-type="RESOURCE_LOCAL">

   <provider>org.hibernate.ejb.HibernatePersistence</provider>

   <class>br.com.solution.models.Usuario</class>

   <properties>


  <property name="hibernate.dialect" 
      value="org.hibernate.dialect.HSQLDialect" />
  <property name="hibernate.show_sql" value="true" />
  <property name="hibernate.format_sql" value="true" />
  <property name="hibernate.hbm2ddl.auto" value="update" />    
   </properties>
 </persistence-unit>

</persistence>
3 respostas

Opa, a exception indica que tem um problema de declaração no seu persistence. olhando assim, não achei. De todo jeito, peguei um exemplo aqui => https://github.com/javaee-samples/javaee7-samples/blob/master/jpa/datasourcedefinition-applicationxml-pu/src/main/resources/META-INF/persistence.xml

Eu copiaria esse persistence. deixaria do seu jeito e veria :).

solução!

Eu desisti do xml kkkk estava muito complicado para a aplicação , resolvi implementar o spring MVC com as configurações de @bean que ele possui. ficou melhor agora posso colocar no projeto e mandar pro cliente. vlw pela forca =). coloco resolvido?

Opa Cleiton, já deixei marcado sua solução como resolvido :).