4

The following used to work in Spring 1.5.10.RELEASE, but does not work in Spring 2.0.7.RELEASE, and I do not know why:

Entity

@Entity
@Table(name = "locations")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Location {
  // ... unimportant stuff
  @Column(name = "c_locations_id")
  private String cLocationId;
  // ... more unimportant stuff
}

Repository (aka "The problem")

@Repository
public interface LocationRepository extends JpaRepository<Location, Long>, JpaSpecificationExecutor<Location> {
  Location findByCLocationId(String cLocationId);
  List<Location> findAllByOrderByCLocationIdAsc();
}

The error I'm getting under Spring 2.0.7.RELEASE for the above code, is

java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [CLocationId] on this ManagedType.

I cannot change the name of the attribute due to other circumstances, so I've tried different variations on the methods in the repository:

  • findBycLocationId - No property orderBycLocationIdAsc found for type Location!
  • findByClocationId - No property clocationId found for type Location! Did you mean 'CLocationId','cLocationId'?
  • findByCLocationId - Unable to locate Attribute with the the given name [CLocationId] on this ManagedType

What does it want?! I just want to upgrade the framework... 😭

2
  • I have sometime some problems when getter and attribute name doesn't match. But I think it's more an IDE problem (it only underline but that compiles). Good to check. Commented Feb 8, 2019 at 14:00
  • Not IDE problem. Maven won't compile... Commented Feb 8, 2019 at 14:03

2 Answers 2

5

You can use method name like this:

Location findByC_Location_Id(String cLocationId);

this can be helpful with references

Sign up to request clarification or add additional context in comments.

Comments

2

You can use @Query annotation in your methods official documentation.

@Query("select l from Location l where l.cLocationId = ?1")
Location findByCLocationId(String cLocationId);

@Query("select l from Location l")
List<Location> findAllByOrderByCLocationIdAsc();

2 Comments

Good workaround, but do I have to? Why did this work in previous version of Spring and not now? Is this type of attribute naming really that unconventional that Spring no longer supports it?
@ØysteinAmundsen To be honest, I don't know. I saw this docs.spring.io/spring-data/jpa/docs/current/reference/html/… but I have not idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.