Announcement Announcement Module
Collapse
No announcement yet.
Problem with Custom Repository Method Names - Get PropertyReferenceException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with Custom Repository Method Names - Get PropertyReferenceException

    Hi,

    I am trying to create a custom JPA repository and have read everything I can find about the subject. The problem is that when I try to run my test, I get:

    Code:
    Caused by: org.springframework.data.mapping.PropertyReferenceException: No property my found for type com.presidioHealth.ppsDataLibrary.domain.presidio.UserMaster
    	at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:74)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:326)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:352)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:352)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:352)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:352)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:352)
    	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:306)
    	at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
    	at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:244)
    	at org.springframework.data.repository.query.parser.Part.<init>(Part.java:73)
    	at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(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.<init>(PartTree.java:240)
    	at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:68)
    	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(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.<init>(RepositoryFactorySupport.java:280)
    	at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:148)
    	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:125)
    	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:41)
    	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
    	... 36 more
    The method name is "myCustomNewPhysicianCustomMethod" and Spring data is trying to indicate that "my" is a property on the object UserMaster. Here are my interfaces and implementation file.

    UserMasterRepositoryCustom.java
    Code:
    public interface UserMasterRepositoryCustom {
    	public abstract void myCustomNewPhysicianCustomMethod(
    			String lastName, 
    			String firstName,
    			String degree,
    			String adtDoctorId,
    			Long organizationId,
    			String locationCode,
    			String emailAddress,
    			String password,
    			Boolean emrOnly,
    			Boolean autoFinalize,
    			Boolean emailMode,
    			String emailOverride);
    }
    UserMasterRepositoryImpl
    Code:
    package com.presidioHealth.ppsDataLibrary.repository.custom;
    
    import javax.persistence.EntityManager;
    import javax.persistence.EntityTransaction;
    import javax.persistence.PersistenceContext;
    import javax.persistence.Query;
    
    import org.eclipse.persistence.annotations.Direction;
    import org.eclipse.persistence.annotations.NamedStoredProcedureQueries;
    import org.eclipse.persistence.annotations.NamedStoredProcedureQuery;
    import org.eclipse.persistence.annotations.StoredProcedureParameter;
    import org.springframework.data.jpa.repository.Modifying;
    
    @NamedStoredProcedureQueries({
    	@NamedStoredProcedureQuery(
    		name="ADDNEWPHYSICIAN",
    		procedureName="addNewPhysician",
    		returnsResultSet=false,
    		parameters={
    			@StoredProcedureParameter(queryParameter="lastName",name="p_lastName", type=String.class),
    			@StoredProcedureParameter(queryParameter="firstName",name="p_firstName", type=String.class),
    			@StoredProcedureParameter(queryParameter="degree",name="p_degree", type=String.class),
    			@StoredProcedureParameter(queryParameter="adtDoctorId",name="p_degree", type=String.class),
    			@StoredProcedureParameter(queryParameter="organizationId",name="p_organizationId", type=Long.class),
    			@StoredProcedureParameter(queryParameter="locationCode",name="p_locationCode", type=String.class),
    			@StoredProcedureParameter(queryParameter="emailAddress",name="p_emailAddress", type=String.class),
    			@StoredProcedureParameter(queryParameter="password",name="p_password", type=String.class),
    			@StoredProcedureParameter(queryParameter="emrOnly",name="p_emrOnly", type=Boolean.class),
    			@StoredProcedureParameter(queryParameter="autoFinalize",name="p_autoFinalize", type=Boolean.class),
    			@StoredProcedureParameter(queryParameter="emailMode",name="p_emailMode", type=Boolean.class),
    			@StoredProcedureParameter(queryParameter="emailOverride",name="p_emailOverride", type=String.class)
    		}
    	)
    })
    public class UserMasterRepositoryImpl implements UserMasterRepositoryCustom {
    
    	@PersistenceContext
    	private EntityManager em;
    	
    	@Override
    	public void myCustomNewPhysicianCustomMethod(String lastName, String firstName,
    			String degree, String adtDoctorId, Long organizationId,
    			String locationCode, String emailAddress, String password,
    			Boolean emrOnly, Boolean autoFinalize, Boolean emailMode,
    			String emailOverride) {
    		do {
    			EntityTransaction etx = em.getTransaction();
    			etx.begin();
    			Query q = em.createNamedQuery("ADDNEWPHYSICIAN");
    			q.setParameter("lastName", lastName);
    			q.setParameter("firstName", firstName);
    			q.setParameter("degree", degree);
    			q.setParameter("adtDoctorId", adtDoctorId);
    			q.setParameter("organizationId", organizationId);
    			q.setParameter("locationCode", locationCode);
    			q.setParameter("emailAddress", emailAddress);
    			q.setParameter("password", password);
    			q.setParameter("emrOnly", emrOnly);
    			q.setParameter("autoFinalize", autoFinalize);
    			q.setParameter("emailMode", emailMode);
    			q.setParameter("emailOverride", emailOverride);
    			try {
    				Object xx = q.getSingleResult();
    				etx.commit();
    			}
    			catch (Exception e) {
    				e.printStackTrace();
    			}
    			finally {
    				em.close();
    			}
    		} while (false);
    		return;
    	}
    
    }
    UserMasterRepository
    Code:
    public interface UserMasterRepository extends JpaRepository<UserMaster, Long>, UserMasterRepositoryCustom {
    	public UserMaster findByLogin(String login);
    }
    Configuration file:
    Code:
    	<jpa:repositories
    		base-package="com.presidioHealth.ppsDataLibrary.repository.presidio" repository-impl-postfix="CustomImpl" />
    My UserMaster object is a typical object that has user properties.

    So, the issue is that no matter what I name my method in my custom repository interface, it always takes the first characters before the first capital letter and tries to match that to a property in the UserMaster object.

    What am I missing?

    Thanks,
    Tom
    Last edited by mrbahr2003; Aug 29th, 2012, 05:10 PM. Reason: added new info

  • #2
    I have situation where I need to build a “select distinct a.address from Person a” (where address is a Address entity inside the Person) kind of query. I am using Specification to dynamically build my where clause and using the findAll(Specification<T>) function to get the result. The problem is I can not use specification to build my select clause and hence can not use findAll(Spcification) function.

    What would be the best way to do something like this?

    Comment


    • #3
      Hi Tom,

      I'm encountering the same issue(s) as you. Did you have any success getting the custom repo working?

      Thanks!

      Eric

      Comment


      • #4
        Any luck with a solution? I am still banging my head over this.

        Regards.

        Comment


        • #5
          Hi Guys,

          Not sure if anyone needs the fix for this but i'll post what i found as it might help people in the future,

          I had the same issue and found that the names of my classes where to blame. I see in the config (in the original post) that the JPA Repos has repository-impl-postfix="CustomImpl" but the implementation class doesn't follow this naming. Change the name of the class to UserMasterRepositoryCustomImpl and it should work.

          Regards

          Comment

          Working...
          X