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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:01:50+00:00 2026-05-15T12:01:50+00:00

If I have something like this @Entity public class Facility { … @ManyToOne @JoinColumn(name=CUSTOMER_FK)

  • 0

If I have something like this

@Entity
public class Facility {
    ...
    @ManyToOne
    @JoinColumn(name="CUSTOMER_FK")
    private Customer customer;
    ...
}

does my @NameQuery like this

@NamedQuery(name="Facility.findByCustomerId", query="select c from Facility c where c.customer=:customer_fk")

or like this

@NamedQuery(name="Facility.findByCustomerId", query="select c from Facility c where c.CUSTOMER_FK=:customer_fk")
  • 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-05-15T12:01:51+00:00Added an answer on May 15, 2026 at 12:01 pm

    You need to stop thinking foreign keys and to start thinking object when using JPQL. Let’s take a closer look:

    select c from Facility c where c.CUSTOMER_FK=:customer_fk
    

    Does your Facility have a CUSTOMER_FK property? No, so the above query is incorrect. Next one:

    select c from Facility c where c.customer=:customer_fk
    

    Syntacticly, this one is correct. But you’re still not thinking object. Here, the query expect you to pass an instance of customer, not a FK. I’d thus rewrite it like this (it is the same query but it communicates IMO the intention much better and I’d actually avoid any foo_fk convention, you don’t really manipulate FK with JPA):

    select c from Facility c where c.customer = :customer
    

    And if you really want to find by id, you should navigate through the association and write:

    select c from Facility c where c.customer.id = :id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Category class which looks like this: @Entity @Table(name = categories) public
I have something like this in my Spring Application: public class Book{ public Book(){
I have this Entity called 'Operation': @Entity @Table(name=operation) public class Operation implements Serializable {
I want to do something like this: @Entity public class Bar { @Id @GeneratedValue
Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
My simplified domain model looks something like this: public abstract class Entity<IdK> { public
If I have entities like: @Entity public class Person { public String name; @OneToMany
I have something like this: public void Delete(T entity) { Context.DeleteObject(entity); Context.SaveChanges(); } I
I have something like this: public class IRepo<T> { } public class EntRepo<T> :
If I have an entity in RIA services like this, [EnableClientAccess] public class ShapeEntity

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.