Announcement Announcement Module
Collapse
No announcement yet.
Spring-data +cdi = No property find found for type class <Entity> Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring-data +cdi = No property find found for type class <Entity>

    Hi,

    I'm trying to use Spring Data JPA with CDI, but I'm not there yet... after fixing the "Unable to resolve a bean for 'javax.persistence.EntityManager'" problem (see http://forum.springsource.org/showth...-EntityManager), I'm getting this error:
    Code:
    java.lang.IllegalArgumentException: No property find found for type class domain.Task
    	at org.springframework.data.mapping.PropertyPath.(PropertyPath.java:73)
    	at org.springframework.data.mapping.PropertyPath.(PropertyPath.java:92)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:319)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:333)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:333)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:333)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:333)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:301)
    	at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:265)
    	at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:239)
    	at org.springframework.data.repository.query.parser.Part.(Part.java:70)
    	at org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:180)
    	at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:260)
    	at org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:240)
    	at org.springframework.data.repository.query.parser.PartTree.(PartTree.java:68)
    	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:57)
    	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:90)
    	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:162)
    	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:68)
    	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.(RepositoryFactorySupport.java:280)
    	at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:148)
    	at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:116)
    	at org.springframework.data.jpa.repository.cdi.JpaRepositoryBean.create(JpaRepositoryBean.java:70)
    	at org.springframework.data.repository.cdi.CdiRepositoryBean.create(CdiRepositoryBean.java:109)
    	at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:61)
    	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:630)
    	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:691)
    	at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:118)
    	at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:691)
    	at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:700)
    	at org.jboss.weld.bean.SessionBean$1$1.proceed(SessionBean.java:175)
    	at com.oracle.injection.provider.weld.WeldInjectionServicesAdapter.aroundInject(WeldInjectionServicesAdapter.java:88)
    	at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:45)
    	at org.jboss.weld.bean.SessionBean$1.inject(SessionBean.java:172)
    	at com.oracle.injection.provider.weld.WeldEjbBeanManager$ExtendedInjectionTarget.inject(WeldEjbBeanManager.java:119)
    	at com.oracle.injection.provider.weld.WeldEjbBeanManager.newBeanInstance(WeldEjbBeanManager.java:82)
    	at weblogic.ejb.container.injection.InjectionBasedEjbComponentCreator.getBean(InjectionBasedEjbComponentCreator.java:75)
    ...
    The problem occurs because the custom interface implementation is not being discovered (everything is working fine with a repository without custom methods).
    I already saw that JpaRepositoryBean.create is calling JpaRepositoryFactory.getRepository that calls getRepository(Class<T> repositoryInterface, Object customImplementation) with customImplementation = null...

    I saw that there is no (spring data) tests using this combination: cdi+custom implementations.

    What am I missing? Is it supported?

    Thanks

  • #2
    Hello

    1) Could you post your Domain class definition and XML configuration?
    2) Why you are using CDI?

    Comment


    • #3
      Originally posted by dr_pompeii View Post
      Hello

      1) Could you post your Domain class definition and XML configuration?
      I'm not using the spring container, so I don't have the XML configuration I think you are talking about.

      About the code...
      Task:
      Code:
      // (getters and imports ommited...)
      
      @Entity(name="TASK")
      public class Task {
      
      	@Id
      	@GeneratedValue
      	@Column(name = "TASK_ID")
      	private Long taskId;
      
      	@Column(name = "CREATED_ON", nullable = false)
      	@Temporal(TemporalType.TIMESTAMP)
      	private Date createdOn;
      
      	@Column(name = "AGENT_ID", nullable = false)
      	private Long agentId;
      
      	@Column(name = "DESCRIPTION")
      	private String description;
      
      	public Task() {
      
      	}
      }
      Repository interface:
      Code:
      public interface SDTaskRepository extends JpaRepository<Task, Long>, SDTaskRepositoryCustom {
      	List<Task> findByStatus(long status);
      }
      Custom interface and implementation:
      Code:
      public interface SDTaskRepositoryCustom {
      	List<Task> findAllTasksForUser(long userId);
      }
      public class SDTaskRepositoryCustomImpl extends SimpleJpaRepository<Task, Long> implements SDTaskRepositoryCustom {
      	private EntityManager entityManager;
      
      	@Inject
          public SDTaskRepositoryCustomImpl(EntityManager entityManager) {
              super(Task.class, entityManager);
              this.entityManager = entityManager;
          }
      	@Override
      	public List<Task> findAllTasksForUser(long userId) {
      		return this.entityManager.createQuery("SELECT * FROM Task t WHERE t.agentId = ?1", Task.class)
      				.setParameter(1, userId).getResultList();
      	}
      }
      The repository client (a test, using arquillian):
      Code:
      @RunWith(Arquillian.class)
      //@Ignore("not working yet: No property find found for type class pt.bes.pp.domain.Task")
      public class SDTaskRepositoryTest {
      
      	@Deployment
          public static Archive<?> createDeployment() {
      		return ShrinkWrap.create(JavaArchive.class).addPackage(Task.class.getPackage()).addPackage(SDTaskRepository.class.getPackage())
      				.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
      				.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
          }
      
      	@Inject
      	SDTaskRepository taskRepository;
      
      	@Test
      	public void testInsertTask() throws Exception {
      		Task task = new Task();
      
      		task = this.taskRepository.save(task);
      
      		Assert.assertTrue(task.getTaskId() != null);
      	}
      
      	@Test
      	public void testFindAllTasksForUser() throws Exception {
      		List<Task> tasks = this.taskRepository.findAllTasksForUser(4L);
      		Assert.assertNotNull(tasks);
      		Assert.assertEquals(3, tasks.size());
      	}
      Integration with CDI:
      Code:
      class EntityManagerFactoryProducer {
      	private static final Logger LOGGER = LoggerFactory.getLogger(EntityManagerFactoryProducer.class);
      
      	@Produces
      	@ApplicationScoped
      	public EntityManagerFactory createEntityManagerFactory() {
      		LOGGER.warn(this.getClass() + " init");
      		return Persistence.createEntityManagerFactory("pp");
      	}
      
      	public void close(@Disposes EntityManagerFactory entityManagerFactory) {
      		entityManagerFactory.close();
      	}
      }
      class UnqualifiedEntityManagerProducer {
      
      	@Produces
      	public EntityManager createEntityManager(
      			EntityManagerFactory entityManagerFactory) {
      		return entityManagerFactory.createEntityManager();
      	}
      
      	public void close(@Disposes EntityManager entityManager) {
      		entityManager.close();
      	}
      
      }
      2) Why you are using CDI?
      ... because I have a constraint in this project to use JEE6 (without the Spring container).


      As a final note, this example is failing also deployed on weblogic. I'm suspecting that the problem is that, as I said in the first post, customImplementation is always null.
      So far, my questions are:
      - is CDI+custom implementations supported?
      - are there another undocumented steps that I'm missing (like the "EntityManagerProducer" that is not mentioned in the reference docs)?


      Thank you.

      Comment

      Working...
      X