2011-08-03 4 views
3

Je me fais une exceptionjava.lang.IllegalArgumentException au printemps-données JPA

<code> 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'auditTrailRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null 
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149) 
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1429) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84) 
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1) 
    at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280) 
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304) 
    ... 24 more 
Caused by: java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null 
    at org.springframework.util.Assert.notNull(Assert.java:112) 
    at org.springframework.util.Assert.notNull(Assert.java:123) 
    at org.springframework.data.jpa.repository.support.SimpleJpaRepository.<init>(SimpleJpaRepository.java:74) 
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:94) 
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:69) 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:146) 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:120) 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:39) 
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142) 
    ... 35 more 

</code> 

Mon référentiel est défini comme

<code> 
public interface AuditTrailRepository extends CrudRepository<AuditTrail, Long>, JpaSpecificationExecutor<AuditTrail> { 


    public List<AuditTrail> findByKey(String key); 

    @Query("select u from AuditTrail u where u.createdDate between :startDate and :endDate ") 
    List<AuditTrail> findByDateRange(@Param("startDate") Date startDate, @Param("endDate") Date endDate); 

    @Query("select u from AuditTrail u where u.createdDate between :startDate and :endDate and key = :clientId ") 
    List<AuditTrail> findByDateRangeForClient(@Param("startDate") Date startDate, 
      @Param("endDate") Date endDate, 
      @Param("ClientId") String clientId); 


} 
</code> 

Mon entité est

<code> 
@Entity 
@Table(name = "AUDIT_TRAIL") 
public class AuditTrail extends BaseEntity { 

    /** 
    * 
    */ 
    private static final long serialVersionUID = -1647646453787027659L; 
    private Long id; 
    // ClientID from 
    private String key; 
    private TaskType taskType; 
    // Inbound/Outbound 
    private FileActionType action; 
    private String userName; 
    private String message; 
    private Date startTime; 
    private Date endTime; 

</code> 

Persitence .xml dans WEB-INF/classes/META-INF est

<code> 
<?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="spring-jpa" /> 

</persistence> 
</code> 

Toute aide appréciée.

répondre à ma propre question ici .......

La seule chose qui a fonctionné pour moi la liste de chaque entité de domaine dans 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="spring-jpa" > 
     <class>com.multiplan.edi.common.domain.AuditTrail</class> 

    </persistence-unit> 

</persistence> 

Répondre

4

La raison pour laquelle vous voyez l'exception posté est que nous avaler une exception lancée par le EntityManager en essayant de rechercher un EntityType à partir du Metamodel. J'ai créé a JIRA issue pour garder une trace de cela.

D'une manière générale, la nécessité de répertorier les classes dépend explicitement de la configuration de votre fournisseur de persistance JPA. Certains d'entre eux peuvent être configurés pour analyser un paquet pour les entités. D'autres exigent de lister au moins les classes racine.

+0

Je viens de vérifier votre problème JIRA, mais il n'y a pas d'activité .. – rokonoid

+0

Quel genre d'activité attendez-vous? Il a été résolu au début de Septembre 20 * 11 * et déjà publié il y a plus d'un an ... –

+0

désolé. Je viens de vérifier. merci btw .. pouvez-vous m'aider une chose, je suis un peu fou d'une exception: https: //gist.github.com/4143358 pouvez-vous s'il vous plaît aider à ce sujet? – rokonoid

Questions connexes