eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Partner – LambdaTest – NPI EA (cat= Testing)
announcement - icon

Distributed systems often come with complex challenges such as service-to-service communication, state management, asynchronous messaging, security, and more.

Dapr (Distributed Application Runtime) provides a set of APIs and building blocks to address these challenges, abstracting away infrastructure so we can focus on business logic.

In this tutorial, we'll focus on Dapr's pub/sub API for message brokering. Using its Spring Boot integration, we'll simplify the creation of a loosely coupled, portable, and easily testable pub/sub messaging system:

>> Flexible Pub/Sub Messaging With Spring Boot and Dapr

1. Introduction

One of the most powerful frameworks that Spring offers programmers for simplifying database interactions in Java applications is the Spring JPA (Java Persistence API). It provides a solid abstraction over JPA.

However, despite the ease of use, developers frequently encounter errors that can be challenging to diagnose and resolve. One such common issue is the “Unable to Locate Attribute with the Given Name” error.

In this tutorial, let’s examine the source of this issue before we investigate how to fix it.

2. Define Use Case

It always helps to have a practical use case to illustrate this article.

We create unique and eye-catching wearable gadgets. After a recent survey, our marketing team found that sorting products by sensor type, price, and popularity on our platform would help customers make better purchasing decisions by highlighting the most popular items.

use case

3. Add Maven Dependencies

Let’s use an in-memory H2 database to create a Wearables table in our project into which we’ll populate sample data that we can use in our testing down the line.

To begin with, let’s add the following Maven dependencies:

<dependency> 
    <groupId>com.h2database</groupId> 
    <artifactId>h2</artifactId> 
    <version>2.2.224</version> 
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <version>2.7.11</version>
</dependency>

4. Add Application Resources

So that we can test this repository, let’s create a few application property entries that help us create and populate a table called WEARABLES into an H2 in-memory database.

In our application’s main/resources folder, let’s create an application-h2.properties with the following entries:

# H2 configuration
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.hbm2ddl.auto=create-drop

# Spring Datasource URL
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1

The below SQL that we will place in the main/resources folder called testdata.sql will help us create the wearables table in the H2 database with a bunch of pre-defined entries:

CREATE TABLE IF NOT EXISTS wearables (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255),
    price DECIMAL(10, 2),
    sensor_type VARCHAR(255),
    popularity_index INT
);

DELETE FROM wearables;

INSERT INTO wearables (id, name, price, sensor_type, popularity_index)
VALUES (1, 'SensaWatch', '500.00', 'Accelerometer', 5);

INSERT INTO wearables (id, name, price, sensor_type, popularity_index)
VALUES (2, 'SensaBelt', '300.00', 'Heart Rate', 3);

INSERT INTO wearables (id, name, price, sensor_type, popularity_index)
VALUES (3, 'SensaTag', '120.00', 'Proximity', 2);

INSERT INTO wearables (id, name, price, sensor_type, popularity_index)
VALUES (4, 'SensaShirt', '150.00', 'Human Activity Recognition', 2);

5. Define WearableEntity Model

Let’s define our entity model WearableEntity. This model is our entity that defines the characteristics of a Wearable device:

@Entity 
public class WearableEntity { 

    @Id @GeneratedValue 
    private Long Id; 
    
    @Column(name = "name") 
    private String Name; 

    @Column(name = "price") 
    private BigDecimal Price; 
    // e.g., "Heart Rate Monitor", "Neuro Feedback", etc. 

    @Column(name = "sensor_type") 
    private String SensorType; 
    
    @Column(name = "popularity_index") 
    private Integer PopularityIndex; 

}

6. Define Query for Entity Filtering

Having introduced the above entity in the platform, let’s add a query to our database that enables our customers to filter WearableEntity, as per the new filter criteria in our persistence layer using the Spring JPA framework.

public interface WearableRepository extends JpaRepository<WearableEntity, Long> {
    List<WearableEntity> findAllByOrderByPriceAscSensorTypeAscPopularityIndexDesc();
}

Let’s break down the above query to understand it better.

  1. findAllBy: Let’s use this method to retrieve all records that are or type WearableEntity
  2. OrderByPriceAsc:  Let’s sort the results by price in ascending order
  3. SensorTypeAsc: After sorting by price, let’s sort by sensorType in ascending order
  4. PopularityIndexDesc: Finally, let’s sort the results by popularityIndex in descending order (as higher popularity might be preferred)

7. Test Repository via Integration Test

Let’s now check the behavior of the WearableRepository  by introducing an integration test in our project:

public class WearableRepositoryIntegrationTest { 
    @Autowired 
    private WearableRepository wearableRepository; 

    @Test 
    public void testFindByCriteria()  {
        assertThat(wearableRepository.findAllByOrderByPriceAscSensorTypeAscPopularityIndexDesc()) .hasSize(4);
    }
}

8. Running Integration Test

But upon running the integration test, we’ll immediately notice that it’s unable to load application context and fails with the following error:

Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [price] on this ManagedType [com.baeldung.spring.data.jpa.filtering.WearableEntity]

9. Understanding the Root Cause

Hibernate uses naming conventions to map fields to database columns. Suppose the field names in an entity class don’t align with the corresponding column names or expected conventions. In that case, Hibernate will fail to map them, causing exceptions during query execution or schema validation.

In this example:

  • Hibernate expects field names like name, price, or popularityIndex (in camelCase), but the entity incorrectly uses the field names Id, Name, SensorType, Price, and PopularityIndex (in PascalCase)
  • When executing a query like findAllByOrderByPriceAsc(), Hibernate will try to map the SQL price column to the entity field. Since the field is named Price (with an uppercase “P”), it fails to locate the attribute, resulting in an IllegalArgumentException

10. Resolving the Error by Fixing the Entity

Let us now change the naming of the fields in our WearableEntity class from PascalCase to camelCase:

@Entity
@Table(name = "wearables")
public class WearableValidEntity {
    @Id
    @GeneratedValue
    private Long id;

    @Column(name = "name")
    // use camelCase instead of PascalCase
    private String name;

    @Column(name = "price")
    // use camelCase instead of PascalCase
    private BigDecimal price;

    @Column(name = "sensor_type")
    // use camelCase instead of PascalCase
    private String sensorType;

    @Column(name = "popularity_index")
    // use camelCase instead of PascalCase
    private Integer popularityIndex;
}

Once we have made this change, let’s rerun the WearableRepositoryIntegrationTest. Voila! It instantly passes.

11. Conclusion

In this article, we’ve highlighted the importance of following JPA naming conventions to prevent runtime errors and ensure smooth data interactions. Adhering to best practices helps avoid field mapping issues and optimizes application performance.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – LSD – NPI (cat=JPA)
announcement - icon

Get started with Spring Data JPA through the reference Learn Spring Data JPA:

>> CHECK OUT THE COURSE

eBook Jackson – NPI EA – 3 (cat = Jackson)