essoal,
Eu fiz duas vezes os exemplos do livro do Yuri Marx e me deparei com o erro abaixo.
(Na dúvida, baixei os fontes do site Ciencia Moderna, mas o erro persiste).
Todas libs foram adicionadas conforme versão indicada no livro.
[color=red]Alguém pode me ajudar?[/color]
A Saída, ao testar o FacadeUsuario:
WARNING: multiple versions of ant detected in path for junit
jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/lib/ant.jar!/org/apache/tools/ant/Project.class
and jar:file:/C:/hibernate/hibernate-3.2/lib/ant-1.6.5.jar!/org/apache/tools/ant/Project.class
Testsuite: facade.UsuarioFacadeTest
29/09/2011 20:45:55 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@45d64c37: display name [org.springframework.context.support.ClassPathXmlApplicationContext@45d64c37]; startup date [Thu Sep 29 20:45:55 BRT 2011]; root of context hierarchy
29/09/2011 20:45:56 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
29/09/2011 20:45:57 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@45d64c37]: org.springframework.beans.factory.support.DefaultListableBeanFactory@6f649b44
29/09/2011 20:45:57 org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from class path resource [jdbc.properties]
29/09/2011 20:45:58 com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
29/09/2011 20:45:59 com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
29/09/2011 20:45:59 org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization
INFO: Bean 'dataSource' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
29/09/2011 20:45:59 org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization
INFO: Bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#739e8329' is not eligible
for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
29/09/2011 20:45:59 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6f649b44: defining beans [propertyConfigurer,dataSource,entityManagerFactory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,
org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,
org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0,
org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,usuario,usuarioDao,usuarioFacade,contato,contatoDao,
contatoFacade,endereco,enderecoDao,enderecoFacade,meioContato,meioContatoDao,meioContatoFacade]; root of factory hierarchy
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 5,068 sec
------------- Standard Error -----------------
29/09/2011 20:45:55 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@45d64c37: display name [org.springframework.context.support.ClassPathXmlApplicationContext@45d64c37]; startup date [Thu Sep 29 20:45:55 BRT 2011]; root of context hierarchy
29/09/2011 20:45:56 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
29/09/2011 20:45:57 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@45d64c37]: org.springframework.beans.factory.support.DefaultListableBeanFactory@6f649b44
29/09/2011 20:45:57 org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from class path resource [jdbc.properties]
29/09/2011 20:45:58 com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
29/09/2011 20:45:59 com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
29/09/2011 20:45:59 org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization
INFO: Bean 'dataSource' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
29/09/2011 20:45:59 org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization
INFO: Bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#739e8329' is not eligible for getting
processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
29/09/2011 20:45:59 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6f649b44: defining beans [propertyConfigurer,dataSource,entityManagerFactory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,
org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,
org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0,
org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,usuario,usuarioDao,usuarioFacade,contato,contatoDao,contatoFacade,
endereco,enderecoDao,enderecoFacade,meioContato,meioContatoDao,meioContatoFacade]; root of factory hierarchy
------------- ---------------- ---------------
Testcase: testGravar(facade.UsuarioFacadeTest): Caused an ERROR
Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Invalid XML in persistence unit from URL [file:/C:/Users/softelli/Desktop/Prj_Agenda/agenda-jar/build/classes/META-INF/persistence.xml]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in class path resource [applicationContext.xml]: Initialization
of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory'
defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Invalid XML in persistence unit from URL [file:/C:/Users/softelli/Desktop/Prj_Agenda/agenda-jar/build/classes/META-INF/persistence.xml]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:596)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:365)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at facade.UsuarioFacadeTest.testGravar(UsuarioFacadeTest.java:47)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Invalid XML in persistence unit from URL [file:/C:/Users/softelli/Desktop/Prj_Agenda/agenda-jar/build/classes/META-INF/persistence.xml]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:308)
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:270)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:122)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:78)
at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:70)
at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:97)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1326)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
Caused by: java.lang.IllegalArgumentException: Invalid XML in persistence unit from URL [file:/C:/Users/softelli/Desktop/Prj_Agenda/agenda-jar/build/classes/META-INF/persistence.xml]
at org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.readPersistenceUnitInfos(PersistenceUnitReader.java:151)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.readPersistenceUnitInfos(DefaultPersistenceUnitManager.java:303)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:275)
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:260)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:192)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element 'persistence' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '1.0'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:417)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3181)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processOneAttribute(XMLSchemaValidator.java:2801)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processAttributes(XMLSchemaValidator.java:2713)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2065)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3103)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:922)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
at org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.validateResource(PersistenceUnitReader.java:187)
at org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.readPersistenceUnitInfos(PersistenceUnitReader.java:138)
Test facade.UsuarioFacadeTest FAILED
test:
Deleting: C:\Users\softelli\AppData\Local\Temp\TEST-facade.UsuarioFacadeTest.xml
CONSTRUÍDO COM SUCESSO (tempo total: 16 segundos)
O applicationContext
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : applicationContext.xml
Created on : 3 de Setembro de 2011, 18:12
Author : softelli
Description: Configuração do Spring Managed Beans para o projeto agenda-rar
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!--
Configurador que substitui os ${...} com os valores definidos no properties file.
Nesse caso, acertos relativos ao JDBC para a definição da fonte de dados abaixo
-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/jdbc.properties"/>
</bean>
<!-- Local C3PO DataSource que trabalha em qualquer ambiente, em ambientes de producao utilize o JNDI -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- JPA EntityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="false"/>
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
</bean>
</property>
</bean>
<!-- Transation Manager para um JPA EntityManagerFactory simples (alternativa ao JTA) -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- Instrui o Spring a realizar o gerenciamento transacional declarativo automatico nas classes anotadas -->
<tx:annotation-driven/>
<!-- PostProcessors para realizar injecao de recursos de acordo com a especificacao JPA (@PersistenceContext, @PersistenceUnit) -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<!-- Processors para realizar a conversao de excecoes nas classes @Repository
(das excessoes nativas como JPA PersistenceExceptions to Spring`s DataException)-->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<!-- Sera automaticamente Transacional gracas ao @Transactional
EntityManager ir'a ser autoinjetado gracaso PersistentContext
Persistence-Exceptions sera auto convertido gracas ao @Repository
Devem ser criados os beans
classe (com id, dominio e scope)
classeDao (com id e class)
classeFacade (com id, class e property (com name e ref))
-->
<bean id="usuario" class="dominio.Usuario" scope="session"/>
<bean id="usuarioDao" class="dao.UsuarioDao" />
<bean id="usuarioFacade" class="facade.UsuarioFacade" >
<property name="usuarioDao" ref="usuarioDao"/>
</bean>
<bean id="contato" class="dominio.Contato" scope="session" />
<bean id="contatoDao" class="dao.ContatoDao"/>
<bean id="contatoFacade" class="facade.ContatoFacade" >
<property name="contatoDao" ref="contatoDao"/>
</bean>
<bean id="endereco" class="dominio.Endereco" scope="session"/>
<bean id="enderecoDao" class="dao.EnderecoDao"/>
<bean id="enderecoFacade" class="facade.EnderecoFacade">
<property name="enderecoDao" ref="enderecoDao" />
</bean>
<bean id="meioContato" class="dominio.MeioContato" scope="session"/>
<bean id="meioContatoDao" class="dao.MeioContatoDao" />
<bean id="meioContatoFacade" class="facade.MeioContatoFacade">
<property name="meioContatoDao" ref="meioContatoDao"/>
</bean>
</beans>
E o 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 http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="agenda-jarPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>dominio.Endereco</class>
<class>dominio.Usuario</class>
<class>dominio.Contato</class>
<class>dominio.MeioContato</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="000000000"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3308/agenda"/>
</properties>
</persistence-unit>
</persistence>