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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:00:08+00:00 2026-05-28T14:00:08+00:00

I used schemaExport to create my tables like this Configuration config = new Configuration();

  • 0

I used schemaExport to create my tables like this

  Configuration config = new Configuration();
  config.addAnnotatedClass(Categories.class);
  config.addAnnotatedClass(Article.class);
  config.configure();
      new SchemaExport(config).create(true, true);

The important pieces of Categories.java and Article.java are these:

Article.java

    @Id
@GeneratedValue
public Long getId() {
    return id;
}

    @OneToMany( cascade = CascadeType.ALL )
public Set<Categories> getCategories() {
    return categories;
}

Categories.java

    @Id
@GeneratedValue
public Long getId() {
    return id;
}

    @ManyToOne(cascade = CascadeType.ALL)
public Article getArticleCategories() {
    return articleCategories;
}

When run, Schema Export generates three tables: Article, Categories and article_categories. article_categories is an association table with two primary keys matching the keys from Article and Categories. Only Article and Categories have been added to the SessionFactory in my ApplicationContext.xml because I obviously don’t have the third table as a class since it was generated. I wrote this HQL:

"from Article a, article_categories ac, Categories c where ac.Article_id = a.id and ac.categories_id = c.id and c.category = 'p'"

Hibernate can’t run it because article_categories is not mapped. Do I need to map it? Is running native SQL instead of HQL a possible alternative, or should I avoid association tables all together? What’s the solution to this issue?

  • 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-28T14:00:09+00:00Added an answer on May 28, 2026 at 2:00 pm

    HQL doesn’t work with tables. It works with entities and their associations. Create joins between the entities in the HQL query, and Hibernate will generate the appropriate SQL, using the join tables, for you.

    Example:

    select a from Article a 
    inner join a.categories c
    where c.category = :categoryName
    

    Read (at least) the HQL section of the reference manual.

    Side note: the name of the entities should be singular: Category and not Categories. An article thus has a Set<Category>, named categories. Much easier to read and understand that way. And the category field of Category should be named name: it’s the name of the category, and not its category.

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

Sidebar

Related Questions

When used like this: import static com.showboy.Myclass; public class Anotherclass{} what's the difference between
Never used a cache like this before. The problem is that I want to
I've used following code to generate database creation script Configuration configuration = new Configuration();
Used to know this, think its something like Ctrl + ??? + F11 .
used image as like map , user can zoom in/out this image.geting x and
I used the LINQ to SQL designer in Visual Studio to create an object
Used this script many times to pass 1 or 2 values to a PHP
I used this code which found on forum without errors in 4.0.2a and now
This is the directory structure of the project (maven2 is used): pom.xml /src /main
used to check user input like username not a login account.

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.