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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:58:55+00:00 2026-05-24T23:58:55+00:00

My Entity Model Class are ——- A ———– private static final long serialVersionUID =

  • 0

My Entity Model Class are

------- A -----------
private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "NameA")
    private String nameA;

    public B getBid() {
        return b;
    }

    public void setBid(B bid) {
        this.b = bid;
    }

    public String getNameA() {
        return nameA;
    }

    public void setNameA(String nameA) {
        this.nameA = nameA;
    }
    @JoinColumn(name = "BID", referencedColumnName = "ID")
    @ManyToOne(fetch= FetchType.LAZY)
    private B b;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
--------------------------------------------
------------------ B -----------------------

private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "NameB")
    private String nameB;


    public String getNameB() {
        return nameB;
    }

    public void setNameB(String nameB) {
        this.nameB = nameB;
    }


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

and
I want to
make this Query session.createQuery("select a.b from A a").list();

with Criteria API ????

  • 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-24T23:58:56+00:00Added an answer on May 24, 2026 at 11:58 pm

    Since you don’t have the inverse relationship, and since Criteria doesn’t allow selecting another entity than the root entity, you’ll have to use a subquery, but it’s ugly:

    DetachedCriteria subquery = DetachedCriteria.forClass(A.class, "a");
    subquery.createAlias("a.b", "b2");
    subquery.setProjection(Projections.property("b2.id"));
    
    Criteria c = session.createCriteria(B.class, "b1");
    c.add(Subqueries.propertyIn("b1.id", subquery));
    

    If you had the inverse OneToMany relationship from B to A, you would just have to do

    Criteria c = session.createCriteria(B.class, "b1");
    c.createAlias("b1.as", "a");
    

    BTW, these non-dynamically constructed queries are better expressed with HQL than with the criteria API. If your real query is the one you asked, just use HQL: it’s more readable and more powerful.

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

Sidebar

Related Questions

HI, I have the following model: @Entity class Flight{ private Airport airportFrom; private Airport
I've got a Page class in my .edmx ADO.NET Entity Data Model file with
Is Model only Entity Data Model class of my database? Model as simple place
Assume I have a such model: class Entity(models.Model): start_time = models.DateTimeField() I want to
I want to use Services(WCF/RIA /Web) to take data from Entity Data Model class
as per my understanding about mvvm is. there is a model (entity class that
I have an entity model where the base class in an inheritance structure has
I have the following Entity model: public class Todo { [Required] public int ID
I've created an Entity Data Model and imported several stored procedures as Function Imports.
I've built a entity framework model against a 2008 database. All works ok against

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.