Java na Web com JSF, Spring, Heibernate e Netbeans

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>

Ninguém? :frowning:

Opa, Boa Tarde.
Estou com o mesmo problema, você conseguiu resolver ?
Att

<persistence version="1.0"...

faz a mudança acima e testa.

Boa tarde, não funcionou.
Para entender certinho, se você puder ler esse post

É que abri esse post, mas não obtive respostas, ai achei esse problema semelhante ao meu.

Desde já agradeço a atenção.

mas o erro continua o mesmo ?
manda o codigo da entity

Segue.

@Entity


package classe.projeto.insumo;

import java.io.Serializable;


import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


import classe.projeto.materiaPrima.MateriaPrima;
import classe.projeto.produtoFinal.ProdutoFinal;
import classe.projeto.unidadeMedida.UnidadeMedida;
import classe.projeto.utils.FiltroQueryAnnotation;

@Entity
@Table(name = "insumo")
public class Insumo implements Serializable{

	private static final long serialVersionUID = 6246670305140563495L;
	
	@EmbeddedId
	private InsumoID					insumoID;
	
	@ManyToOne
	@JoinColumn(name = "produtoID", referencedColumnName="produtoID", insertable = false, updatable = false)
	private ProdutoFinal	produtoFinal;
	
	@ManyToOne
	@JoinColumn(name = "materiaPrimaID", nullable = false)
	private MateriaPrima materiaPrima;
	
	@ManyToOne
	@JoinColumn(name="unidadeMedidaID", nullable = false)
	private UnidadeMedida unidadeMedida;
	
	@Column(nullable = false)
	private Double quantidade;
	
	@FiltroQueryAnnotation(camposFiltro = "insumoID,produtoID" , tipoDado = "objeto,objeto", objetoRelacionado="insumoID", metodoRelacionado="getInsumoID,getProduto")
	public InsumoID getInsumoID() {
		return insumoID;
	}
	
	public void setInsumoID(InsumoID insumoID) {
		this.insumoID = insumoID;
	}

	@FiltroQueryAnnotation(camposFiltro = "produtoID" , tipoDado = "int", objetoRelacionado="produtoFinal", metodoRelacionado="getProdutoID")
	public ProdutoFinal getProdutoFinal() {
		return produtoFinal;
	}

	public void setProdutoFinal(ProdutoFinal produtoFinal) {
		this.produtoFinal = produtoFinal;
	}

	@FiltroQueryAnnotation(camposFiltro = "materiaPrimaID" , tipoDado = "int", objetoRelacionado="materiaPrima", metodoRelacionado="getProdutoID")
	public MateriaPrima getMateriaPrima() {
		return materiaPrima;
	}
	
	public void setMateriaPrima(MateriaPrima materiaPrima){
		this.materiaPrima = materiaPrima;
	}
	
	@FiltroQueryAnnotation(camposFiltro = "unidadeMedidaID" , tipoDado = "objeto", objetoRelacionado="unidadeMedida", metodoRelacionado="getUnidadeMedidaID")
	public UnidadeMedida getUnidadeMedida() {
		return unidadeMedida;
	}
	
	public void setUnidadeMedida(UnidadeMedida unidadeMedida){
		this.unidadeMedida = unidadeMedida; 
	}
	
	@FiltroQueryAnnotation(camposFiltro = "quantidade" , tipoDado = "boolean")
	public Double getQuantidade(){
		return quantidade;
	}
	
	public void setQuantidade(Double quantidade){
		this.quantidade = quantidade;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((insumoID == null) ? 0 : insumoID.hashCode());
		result = prime * result
				+ ((materiaPrima == null) ? 0 : materiaPrima.hashCode());
		result = prime * result
				+ ((produtoFinal == null) ? 0 : produtoFinal.hashCode());
		result = prime * result
				+ ((quantidade == null) ? 0 : quantidade.hashCode());
		result = prime * result
				+ ((unidadeMedida == null) ? 0 : unidadeMedida.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Insumo other = (Insumo) obj;
		if (insumoID == null) {
			if (other.insumoID != null)
				return false;
		} else if (!insumoID.equals(other.insumoID))
			return false;
		if (materiaPrima == null) {
			if (other.materiaPrima != null)
				return false;
		} else if (!materiaPrima.equals(other.materiaPrima))
			return false;
		if (produtoFinal == null) {
			if (other.produtoFinal != null)
				return false;
		} else if (!produtoFinal.equals(other.produtoFinal))
			return false;
		if (quantidade == null) {
			if (other.quantidade != null)
				return false;
		} else if (!quantidade.equals(other.quantidade))
			return false;
		if (unidadeMedida == null) {
			if (other.unidadeMedida != null)
				return false;
		} else if (!unidadeMedida.equals(other.unidadeMedida))
			return false;
		return true;
	}

}

@Repository


package classe.projeto.insumo;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import classe.projeto.utils.DAOException;
import classe.projeto.utils.FiltroQuery;
import classe.projeto.utils.GlossarioMensagens;
import classe.projeto.utils.ValidaOrdenacaoLimit;

@Repository("insumoDAO")
public class InsumoDAO implements IInsumoDAO {

	private String filtroQuery;
	
	@Autowired
	private SessionFactory factory;

	private void setFiltroQuery(Insumo insumo){
		FiltroQuery	filtroQuery		=	new FiltroQuery();
		this.filtroQuery 			=	filtroQuery.montarFiltro(insumo);
	}
	
	@Override
	public void salvar(Insumo insumo) throws DAOException{
		
		try {
			factory.getCurrentSession().save(insumo);
			factory.getCurrentSession().flush();
		} catch (Exception e) {
			throw new DAOException(GlossarioMensagens.getInstance().getMSG04());
		}finally{
			factory.getCurrentSession().clear();
		}
		
	}

	@Override
	public void atualizar(Insumo insumo) throws DAOException{
		
		try {
			factory.getCurrentSession().merge(insumo);
			factory.getCurrentSession().flush();
		} catch (Exception e) {
			throw new DAOException(GlossarioMensagens.getInstance().getMSG05());
		}finally{
			factory.getCurrentSession().clear();
		}
		
	}
	
	@Override
	public void excluir(Insumo insumo) throws DAOException{
		try {
			factory.getCurrentSession().delete(insumo);
			factory.getCurrentSession().flush();
		} catch (Exception e) {
			throw new DAOException(GlossarioMensagens.getInstance().getMSG06());
		}finally{
			factory.getCurrentSession().clear();
		}
	}
	
	@Override
	public Insumo obter(Insumo insumo) {
		
		this.setFiltroQuery(insumo);
		String sql			   	= 	"SELECT * FROM vwlistainsumo " + this.filtroQuery ;
		Query consulta	        =	factory.getCurrentSession().createSQLQuery(sql).addEntity(Insumo.class);
		return (Insumo)			consulta.uniqueResult();
		
	}
	
	@SuppressWarnings("deprecation")
	@Override
	public Integer maxInsumoID(Insumo insumo){
		
		this.setFiltroQuery(insumo);
		
		String sql				= 	"SELECT insumoID FROM vwmaxinsumoid " + this.filtroQuery ;
		Query consulta	        =	factory.getCurrentSession().createSQLQuery(sql).addScalar("insumoID", Hibernate.INTEGER);
		Integer insumoID		=   (Integer) consulta.uniqueResult();
		
		return 	insumoID;
	}
	
	@SuppressWarnings("deprecation")
	@Override
	public Integer totalRegistros() {
		String sql			   	= 	"SELECT COUNT(*) AS totalRegistros FROM vwlistainsumo " ;
		Query consulta	        =	factory.getCurrentSession().createSQLQuery(sql).addScalar("totalRegistros", Hibernate.INTEGER);
		Integer totalRegistros  =   (Integer) consulta.uniqueResult();
		return totalRegistros;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Insumo> pesquisar(Insumo insumo, String campoOrdenacao, String ordenacao, Integer pagina, Integer limit) {
		
		this.setFiltroQuery(insumo);
		String sql			   		= 	"SELECT * FROM vwlistainsumo " + this.filtroQuery;
		sql							=	ValidaOrdenacaoLimit.ValidaOrdenacaoLimit(sql, campoOrdenacao, ordenacao, pagina, limit);
		Query consulta	        	=	factory.getCurrentSession().createSQLQuery(sql).addEntity(Insumo.class);
		List<Insumo> listaInsumo  	=	consulta.list();
		return listaInsumo;		
			
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Insumo> pesquisarInsumoPorMateriaPrimaEProduto(Integer materiaPrimaID, Integer produtoFinalID) {
		String sql			   		= 	"SELECT * FROM vwlistainsumo WHERE materiaPrimaID = " + materiaPrimaID + "AND produtoID = " + produtoFinalID;
		Query consulta	        	=	factory.getCurrentSession().createSQLQuery(sql).addEntity(Insumo.class);
		List<Insumo> listaInsumo  	=	consulta.list();
		return listaInsumo;		
	} 
	
}

@Service


package classe.projeto.insumo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import classe.projeto.produtoFinal.ProdutoFinal;
import classe.projeto.utils.DAOException;
import classe.projeto.utils.GlossarioMensagens;
import classe.projeto.utils.RNException;

@Service("insumoRN")
@Transactional
public class InsumoRN implements IInsumoRN{

	@Autowired
	private IInsumoDAO insumoDAO;
	
	public void salvar(Insumo insumo) throws RNException{
		
		InsumoID 		insumoID		=	new InsumoID();
		Insumo 			insumoTemp		=	new Insumo();
		
		List<Insumo> listaInsumo	=	this.insumoDAO.pesquisarInsumoPorMateriaPrimaEProduto(insumo.getMateriaPrima().getProdutoID(), insumo.getProdutoFinal().getProdutoID());
		
		if((listaInsumo.isEmpty() || listaInsumo.size() == 0) && insumo.getInsumoID() == null){
			try {
				
				insumoTemp						=	new Insumo();
				ProdutoFinal 	produtoFinal	=	new ProdutoFinal();
				produtoFinal.setProdutoID(insumo.getProdutoFinal().getProdutoID());
				insumoTemp.setProdutoFinal(produtoFinal);
				insumoID.setProduto(insumo.getProdutoFinal().getProdutoID());
				insumoID.setInsumoID(this.maxInsumoID(insumoTemp));
				insumo.setInsumoID(insumoID);
				
				this.insumoDAO.salvar(insumo);
			} catch (DAOException dao) {
				throw new RNException(dao.getMessage());
			}
			
		}else{

			if(listaInsumo.size() > 1){
				throw new RNException(GlossarioMensagens.getInstance().getMSG27());
			}else{
				try {
					insumo.setInsumoID(listaInsumo.get(0).getInsumoID());
					this.insumoDAO.atualizar(insumo);
				} catch (DAOException dao) {
					throw new RNException(dao.getMessage());
				}
			}
		}
		
	}
	
	public void excluir(Insumo insumo) throws RNException{
		try {
			this.insumoDAO.excluir(insumo);
		} catch (DAOException dao) {
			throw new RNException(dao.getMessage());
		}
	}

	@Transactional(readOnly=true)
	public Integer totalRegistros(){
		return this.insumoDAO.totalRegistros();
	}
	
	@Transactional(readOnly=true)
	public Insumo obter (Insumo insumo){
		return this.insumoDAO.obter(insumo);
	}
	
	@Transactional(readOnly=true)
	public List<Insumo> pesquisar(Insumo insumo, String campoOrdenacao, String ordenacao, Integer pagina,  Integer limit){
		return this.insumoDAO.pesquisar(insumo, campoOrdenacao, ordenacao, pagina, limit);
	}

	
	private Integer maxInsumoID(Insumo insumo){
		Integer retorno = this.insumoDAO.maxInsumoID(insumo); 
		if(retorno == null){
			return 1;
		}
		return retorno + 1;
	}

	
}

e o Bean


package classe.projeto.bean;

import java.io.IOException;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;

import org.primefaces.event.RowEditEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import classe.projeto.insumo.IInsumoRN;
import classe.projeto.insumo.Insumo;
import classe.projeto.insumo.InsumoID;
import classe.projeto.produtoFinal.IProdutoFinalRN;
import classe.projeto.produtoFinal.ProdutoFinal;
import classe.projeto.utils.GlossarioTexto;
import classe.projeto.utils.RNException;

@Named("insumoCadastroBean")
@Controller
@Scope("view")
public class InsumoCadastroBean {

	private Insumo       insumo						=	new Insumo();
	private ProdutoFinal produtoFinal 				= 	new ProdutoFinal();
	private List<Insumo> listaInsumos;
	
	@Autowired
	private IInsumoRN insumoRN;
	
	@Autowired 
	private IProdutoFinalRN produtoFinalRN;
	
	@PostConstruct
	public void init() {
		
		String produtoID		=	FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("produto");
		String insumoID			=	FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("insumo");
		
		if(produtoID == null){
			this.redirectPagina();
		}else{
			
			this.produtoFinal.setProdutoID(Integer.parseInt(produtoID));
			this.produtoFinal	=	produtoFinalRN.obter(this.produtoFinal);
			
			/*
			 * Se o insumoID estiver vazio, significa que o usuario esta vindo da tela
			 * de produtofinal, e se não tiver significa que esta tentando excluir um insumo
			 */
			
			if(insumoID == null || (insumoID.equals("") || insumoID.length() == 0)){
					
				this.insumo.setProdutoFinal(this.produtoFinal);
				this.listaInsumos			=	this.getListaInsumos();

			}else{
				
				InsumoID 		insumoIDTemp		=	new InsumoID();
				ProdutoFinal	produtoFinalTemp	=	new ProdutoFinal();
				
				insumoIDTemp.setInsumoID(Integer.parseInt(insumoID));
				insumoIDTemp.setProduto(this.produtoFinal.getProdutoID());
				
				produtoFinalTemp.setProdutoID(this.produtoFinal.getProdutoID());
				
				this.insumo.setProdutoFinal(produtoFinalTemp);
				this.insumo.setInsumoID(insumoIDTemp);
				
				this.insumo			=	insumoRN.obter(this.insumo);
				this.excluir();
			}
						
		}
		
	}
	
	public void salvar(){
		
		try {
			insumoRN.salvar(this.insumo);
			this.insumo	=	new Insumo();
			//Setando novamente o produtoFinal, para que no proximo cadastro o sistema consigo gerar a PK certinho
			this.insumo.setProdutoFinal(this.produtoFinal);
		} catch (RNException rn) {
			
			FacesContext context 	= 	FacesContext.getCurrentInstance();
			FacesMessage msg 	 	=	new FacesMessage(FacesMessage.SEVERITY_ERROR,GlossarioTexto.getInstance().getErro(),rn.getMessage());
			context.addMessage("boxMensagemValidacao", msg);
		}
		
	}
	
	private void excluir(){
		
		try {
			insumoRN.excluir(this.insumo);
		} catch (RNException rn) {
			
			FacesContext context 	= 	FacesContext.getCurrentInstance();
			FacesMessage msg 	 	=	new FacesMessage(FacesMessage.SEVERITY_WARN,rn.getMessage(),null);
			context.addMessage("boxMensagemValidacao", msg);
		}
		
	}
	
	public void rowEdit(RowEditEvent rowEdit){
		Insumo insumoTemp	=	(Insumo) rowEdit.getObject();
		this.insumo			=	insumoTemp;
		this.salvar();
	}
	
	private void redirectPagina(){
		
		try {
			FacesContext.getCurrentInstance().getExternalContext().redirect("../produtoFinal/index.html");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	public Insumo getInsumo() {
		return insumo;
	}

	public void setInsumo(Insumo insumo) {
		this.insumo = insumo;
	}
	
	public List<Insumo> getListaInsumos() {
		
		Insumo insumoTemp				=		new Insumo();
		ProdutoFinal produtoFinalTemp	=		new ProdutoFinal();
		produtoFinalTemp.setProdutoID(this.produtoFinal.getProdutoID());
		
		insumoTemp.setProdutoFinal(produtoFinalTemp);
		this.listaInsumos				=	insumoRN.pesquisar(insumoTemp, "materiaprimaID", "ASC", null, null);
		return this.listaInsumos;
	}

	public ProdutoFinal getProdutoFinal() {
		return produtoFinal;
	}

	public void setProdutoFinal(ProdutoFinal produtoFinal) {
		this.produtoFinal = produtoFinal;
	}
	
}

eu trocaria @Autowired por @Service(“xxx”) no bean e @Qualifier(“xxx”) onde vc ta injetando

Ok irei tentar, mas como sou iniciante, terias como me explicar a diferença entre o @Autowired e o @Qualifier.
Obrigado

Testei e não funcionou, fiz conforme exemplo do site do Spring

@Autowired
@Qualifier("XXX")

Existe alguma maneira de condicionar a injeção de dependência ?

eu disse pra tirar o @autowired
nao usa o qualifier do spring e sim do java pra fazer injeção de dependencia.

outro ponto é que vc precisa a aprender a interpretar os erros, ou pelo menos postá-los.

Ok, irei testar e ver se com o @Qualifier do java funciona.
Obrigado