Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8454363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:00:34+00:00 2026-06-10T12:00:34+00:00

I am using spring-data and a jpa repository for my queries. I am having

  • 0

I am using spring-data and a jpa repository for my queries. I am having a problem where, I have an entity with a ManyToOne field, if I order by this field in a query, then any values that have a Null for this field are not returned in my list. This doesn’t seem like proper behaviour.

Here are what my entities look like:

@Entity
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@NotNull
@Column(name = "id")
private Integer id;


@Size(max = 255)
@Column(name = "name")
private String name;

@JoinColumn(name = "owner_user_id", referencedColumnName = "id")
@ManyToOne(fetch = FetchType.LAZY)
private User ownerUserId;

}

Then the ManyToOne user entity

@Entity
public class User {

@Size(max = 100)
@Column(name = "email")
private String email;
@Size(max = 256)
@Column(name = "first_name")
private String firstName;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@NotNull
@Column(name = "id")
private Integer id;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "ownerUserId", fetch = FetchType.LAZY)
private Collection<Item> itemCollection;


}

I have my JPA repository like so:

@Transactional
public interface ItemRepository extends JpaRepository<Item, Integer> {

 @Query("FROM Item i where name = ?1");
 Page<Item> findItemWithName(String name, Pageable pageable);
}

I have simplified a lot of the code just so you can get an idea. All the queries are working great, the problem arises when I set the Sort in my Pageable object to sort on the owner_user_id column. If any of the entries in the item table have a null for owner_user_id they are not returned in the list.

Is there some sort of annotation I can add to get around this? Or something else I can do? I really want to keep using the repository but don’t think I will if I can’t get around this. I am using hibernate and MYSQL, not sure if that is part of the issue.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:00:35+00:00Added an answer on June 10, 2026 at 12:00 pm

    This was a known issue in Spring Data / JPA Spec which is solved in 1.2.1 Version. See https://jira.springsource.org/browse/DATAJPA-252 and https://jira.spring.io/browse/DATAJPA-277.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem. I have spring 3.0.5, using its new DATA JPA repository
I've switched from using Spring Data JPA for regular DAO objects with Entity Manager
I'm using Spring-Data-JPA 1.0.3.RELEASE to manage my ORM. my persistence.xml looks like this: <persistence>
While using Spring Data JPA in an application, you typically define your entities (@Entity)
I'm using Spring data neo4j 2.1.0.BUILD-SNAPSHOT and Neo4j 1.6.1 server. I have a Friendship
Im using this code: protected String getContactInfo() { Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null,
I've got an Eclipse Maven project for spring-data-jpa and QueryDsl. I seem to have
Does anyone have an idea how I can use Spring Data JPA and use
I'm having trouble retrieving data from my database using Spring Jdbc. Here's my issue:
I have an JPA/Hibernate/Spring/Tomcat web application with second level data cache enabled for performance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.