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

  • Home
  • SEARCH
  • 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 8617009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:45:19+00:00 2026-06-12T05:45:19+00:00

I have a class declared as @Entity @Table(name = word, schema = public) public

  • 0

I have a class declared as

@Entity
@Table(name = "word", schema = "public")
public class Word implements java.io.Serializable {
    ...
    private ContentLanguage contentLanguage;
    ...
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "content_language_id", nullable = false)
    public ContentLanguageT getContentLanguage() {
        return this.contentLanguage;
    }

    public void setContentLanguage(ContentLanguage contentLanguage) {
        this.contentLanguage = contentLanguage;
    }
  ...

ContentLanguage is declared as

    @Entity
    @Table(name = "content_language", schema = "public")
    public class ContentLanguage implements java.io.Serializable {

        private int id;
        private String value;
 ....

My action needs to query for all Words who’s ContentLanguage field has an id = 1
I thought I might be able to create a criteria against ContentLanguage class and then add this to a Criteria against the Word table but obviously this is not the way to do it.
Any ideas as I don’t want to have to go and start using SQL or HQL for what is a relatively simple task?

                public String execute() 
    {       
        //DetachedCriteria criteria1 = DetachedCriteria.forClass(ContentLanguageT.class);
        //criteria1.add(Restrictions.eq("id",1));
        DetachedCriteria criteria = DetachedCriteria.forClass(WordT.class);
        //criteria.add( criteria1 );
        criteria.add(Restrictions.eq("contentLanguageT", Integer.valueOf( contentLangID )));        
        allWords = wordDao.findByCriteria( criteria, 0, 50);        
        return SUCCESS;
    }
  • 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-12T05:45:20+00:00Added an answer on June 12, 2026 at 5:45 am

    Word.contentLanguage is of type ContentLanguage. SO you can’t compare it with an integer. You may only compare it with a ContentLanguage. So, either you do

    criteria.add(Restrictions.eq("contentLanguage.id", contentLanguageId));
    

    or you do

    criteria.add(Restrictions.eq("contentLanguage", 
                                 session.load(ContentLanguage.class, contentLanguageId)));
    

    I really prefer HQL for such simple static queries. Isn’t the following much more readable and intuitive?

    select w from Word w 
    where w.contentLanguage.id = :contentLanguageId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a java class which is package-private (declared with class, not public
I have an entity which is declared roughly like: @Entity @Table(name = myUserTable) public
I have a tags property declared like that : @Entity public class BlogArticle {
I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need
I have a class declared as: public class Foo<T> : Panel where T :
I have an abstract method in a base class declared like so... public abstract
I have declared a class as class DCFrameListener : public FrameListener, public OIS::MouseListener, public
WorkAround: I have declared a class level Public static variable and initialized with a
I have the fallowing mapping: <class name=Country table=Country lazy=false > <cache usage=read-write/> <id name=Id
I have my default schema declared in persistence.xml as: <property name=hibernate.default_schema value=MYSCHEMA /> However,

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.