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 7959591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:35:51+00:00 2026-06-04T04:35:51+00:00

I have simple Entitly class with the @EmbeddedId ( Integer and String fields in

  • 0

I have simple Entitly class with the @EmbeddedId (Integer and String fields in separate class). And I use the Spring Data (org.springframework.data.jpa.repository.JpaRepository) to access the database (MySql), with the normal Id the queries are working fine, both the generated by Spring and the ones wrote by myself. With the EmbeddedId I didnt manage to create the correct query. What I want to do is to select all the id (one of the fields of embeddedId for which some condition occurs) Here you have some code samples, maybe somebody will have an idea how to solve it.
The entity class:

@Entity
@Table(name="table_name")
public class EntityClass {

    @EmbeddedId
    private EmbeddedIdClass id;
    private String  someField;
    //rest of implemetation
}

the EmbeddedId class:

@Embeddable
public class EmbeddedIdClass implements Serializable {

public EmbeddedIdClass(Long id, String language) {
    super();
    this.id = id;
    this.language = language;
}

public UserAdTextId() {}        

@Column(name="ad_id", nullable=false)
    private Integer id;

    @Column(name="language_code", nullable=false)
    private String  language;
    //rest of implemetation
}

and the repository:

@Transactional(readOnly=true)
public interface MyRepository extends JpaRepository<EntityClass, EmbeddedIdClass> {
    @Query("select distinct ad_id from EntityClass where userId = :userId and (/*here the conditions*/)")
    public Page<Integer> findUserAdsWithSearchString(@Param("userId") Integer userId, @Param("searchString") String searchString, Pageable page);
//rest of implemetation
}

I didn’t find any documentation how to create the methods for supporting the @EmbeddedId, I was trying many different method names, but I always get exceptions from the method parser..

  • 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-04T04:35:53+00:00Added an answer on June 4, 2026 at 4:35 am

    It seems your query is using column names. It should contain the property names, including navigation into embedded objects. There’s also a related question here on SO: How to write JPQL SELECT with embedded id?

    select distinct id.id from EntityClass where userId = :userId and (...)
    

    The first id refers to attribute id of EntityClass (of type EmbeddedIdClass), and the second one refers to the id property of EmbeddedIdClass.

    Also, make sure there’s a userId property in EntityClass.

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

Sidebar

Related Questions

I have a simple entity called Store built in Xcode's data modeler for use
I have a very simple JPA entity. It features some simple metadata fields, and
I have a number of simple controller classes that use Doctrine's entity manager to
I have simple SSIS package which reads data from flat file and insert into
I have a simple JPA entity that uses a generated long ID as its
I have a simple question regarding Entity declaration in JPA. I have an entity
I have a simple class Role: @Entity @Table (name = ROLE) public class Role
I have a simple JPA project running (with IBM RAD 7.5 on WebSphere 7).
I am using Spring 3.0.5, Hibernate 3.6.7 and Vaadin. I have a simple entity
I have the following (simple) mapping: @Entity public class Role { @OneToMany( fetch =

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.