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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:49:03+00:00 2026-06-17T21:49:03+00:00

There are two tables with @OneToMany and @ManyToOne bidirectional relation, like this: @Entity public

  • 0

There are two tables with @OneToMany and @ManyToOne bidirectional relation, like this:

@Entity
public class Asset {
    private int id;
    private int count;
    @OneToMany
    private Set<Dealing> dealings;
...
}

@Entity
public class Dealing {

    private int id;
        ...
    @ManyToOne
    @JoinColumn(name = "customer_id", nullable = false, updatable = false)
    private Customer customer;
    @ManyToOne
    @JoinColumn(name = "product_id", nullable = false, updatable = false)
    private Product product;
    @ManyToOne(cascade = CascadeType.ALL)
    private Asset asset;
}

all things sound OK, but when I want to search data using Restriction like this,

session.createCriteria(Asset.class).add(Restrictions.eq("dealings.customer.id", customerId)).add(Restrictions.eq("dealing.product.id", productId)).list();

In this level I get this error,

could not resolve property: dealings.customer of: com.project.foo.model.Asset

one of the solutions are to change my strategy but i wasted time to find this,btw I don’t have any idea about it, do you ?

  • 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-17T21:49:04+00:00Added an answer on June 17, 2026 at 9:49 pm

    First of all, you don’t have a bidirectional OneToMany association, but two unrelated unidirectional associations. In a bidirectional OneToMany association the One side must be marked as the inverse of the Many side using the mappedBy attribute:

    @OneToMany(mappedBy = "asset")
    private Set<Dealing> dealings;
    

    Second, using the criteria API for such static queries is overkill, and leads to code that is harder to read than necessary.I would simply use HQL which is much easier to read. Criteria should be used for dynamic queries, IMHO, but not for static ones:

    select asset from Asset asset 
    inner join asset.dealings dealing
    where dealing.customer.id = :customerId
    and dealing.product.id = :productId
    

    Whether you use HQL or Criteria, you can’t use asset.dealings.customer, since asset.dealings is a collection. A collection doesn’t have a customer attribute. To be able to reference properties from the Dealing entity, you need a join, as shown in the above HQL query. And it’s the same for Criteria:

    Criteria criteria = session.createCriteria(Asset.class, "asset");
    criteria.createAlias("asset.dealings", "dealing"); // that's an inner join
    criteria.add(Restrictions.eq("dealing.customer.id", customerId);
    criteria.add(Restrictions.eq("dealing.product.id", productId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

there are two entity classes: @Entity public class Place implements Serializable { @Id @GeneratedValue(strategy
I have two entities. Sports: @Entity public class Sports implements Serializable { private static
@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public class Problem { @ManyToOne private Person person; } @Entity
There are two tables, namely LongTable and ShortTable . For example, LongTable looks like:
There are two tables, categories and books and I'd like to select all books
I have two entites, Person and Teacher , with a OneToMany relationship: public class
Given the following two entities : class Parent { @OneToMany(cascade=CascadeType.ALL) private Set<Child> children; (...)
There are two tables Users:Id(PK int), Username(varchar (50)) Emails:Id(PK int), UserId(FK int), Subject(varchar(50)), Content(varchar(250)),
I have two models. @Entity public class Student { @Id @GeneratedValue(strategy=GenerationType.AUTO) protected long id;
There are two tables: |idperson|workload|active|idpm|firstname|lastname| |idsupportday|date|fk_person| and this SQL statement: SELECT person.idperson, person.firstname, person.lastname,

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.