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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:25:40+00:00 2026-06-10T11:25:40+00:00

Suppose I have an entity like this: @Entity @Table(name = ITEMS) public class Item

  • 0

Suppose I have an entity like this:

@Entity
@Table(name = "ITEMS")
public class Item  {
    @OneToMany(mappedBy = "item")
    private Set<ItemParameterValue> parameterValues;
}

It has a relation with ItemParameterValues:

@Entity
@Table(name = "ITEM_PARAMETER_VALUES", uniqueConstraints = @UniqueConstraint(columnNames = {"item_id", "parameter_id"}))
    public class ItemParameterValue {
        @ManyToOne
        @JoinColumn(name = "parameter_id")
        private ItemParameter parameter;
}

which has a relation with ItemParameter:

@Entity
@Table(name = "ITEM_PARAMETERS", uniqueConstraints = @UniqueConstraint(columnNames = "sid"))
public class ItemParameter {

}

So for example I have some Item which has a parameter value of “220” which has a parameter named “Voltage”. I have to filter for 220 but the value 220 can belong to many parameters, I need the one which belongs to the parameter “Voltage”.

I know I can do something like this (assuming I set up the proper aliases):

Criteria c = session.createCriteria(Item.class);
// ...
c.add(Restrictions.conjunction()
    .add(Restrictions.eq("item.parameterValue", "220"))
    .add(Restrictions.eq("item.parameterValue.parameter.sid", "Voltage")));

but it seems somewhat cumbersome to me. Is there a more convenient way to handle this kind of relation?

  • 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-10T11:25:41+00:00Added an answer on June 10, 2026 at 11:25 am

    instead of createalias you can use createcriteria to shorten it

    Criteria c = session.createCriteria(Item.class)
        .createCriteria("parameterValues")
            .add(Restrictions.eq("theProperty", "220"))
            .createCriteria("parameter")
                .add(Restrictions.eq("sid", "Voltage"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have public class Product: Entity { public IList<Item> Items { get; set;
Technology: Hibernate 3.0 Suppose i have Entity class Company @Entity @Table(name=tbl_companies) public class Company
Suppose I have an entity in Fluent NHibernate that looks like this: public class
Suppose i have a classes like this @Entity public class Customer implements Serializable {
Suppose I have an entity object defined as public partial class Article { public
Suppose I have the following 2 entities: @Entity public class Person implements Serializable {
Suppose I have public IList<Entity> Children { get; set; } public NotifyChildren(Func<object, bool> action,
Suppose you have a method: public void Save(Entity data) { this.repositoryIocInstance.EntitySave(data); } Would you
Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
I'm trying out Entity Framework Code first CTP4. Suppose I have: public class Parent

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.