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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:19:41+00:00 2026-05-31T03:19:41+00:00

First of all I’m really sorry for asking such a basic thing, I know

  • 0

First of all I’m really sorry for asking such a basic thing, I know it can be irritating, but I want to know if I make a move in the wrong direction. Of course, I will get to the step-by-step reading of the documentation, but now all I want is to solve this problem.

I want to select values from two tables with many-to-one association (each category may suit different computers).

+------------+             +------------+ 
|computers   |             |categories  | 
+------------+             +------------+ 
|categoryId  |------------>|categoryId  | 
|computerId  |             |categoryName| 
|computerName|             +------------+ 
+------------+

Here are the automatically generated POJO classes:

@Table(name="computers", catalog="dbname") 
public class Computers  implements java.io.Serializable { 

    private Integer computerId; 
    private Categories categories; 
    private String computerName; 

    public Computers() { 
    } 

    public Computers(Categories categories, String computerName) { 
        this.categories = categories; 
        this.computerName = computerName; 
    } 

    @Id
    @GeneratedValue(strategy=IDENTITY) 
    @Column(name="computerId", unique=true, nullable=false) 
    public Integer getComputerId() { 
        return this.computerId; 
    } 

    public void setComputerId(Integer computerId) { 
        this.computerId = computerId; 
    } 

    @ManyToOne(fetch=FetchType.LAZY) 
    @JoinColumn(name="categoryId", nullable=false) 
    public Categories getCategories() { 
        return this.categories; 
    } 

    public void setCategories(Categories categories) { 
        this.categories = categories; 
    } 

    @Column(name="computerName", nullable=false) 
    public String getComputerName() { 
        return this.computerName; 
    } 

    public void setComputerName(String computerName) { 
        this.computerName = computerName; 
    } 

} 



@Entity
@Table(name="categories"
    ,catalog="dbname"
) 
public class Categories  implements java.io.Serializable { 


     private Integer categoryId; 
     private String categoryName; 
     private Set<Computers> computerss = new HashSet<Computers>(0); 
     private Set<Customers> customerss = new HashSet<Customers>(0); 

    public Categories() { 
    } 

    public Categories(String categoryName) { 
        this.categoryName = categoryName; 
    } 
    public Categories(String categoryName, Set<Computers> computerss, Set<Customers> customerss) { 
       this.categoryName = categoryName; 
       this.computerss = computerss; 
       this.customerss = customerss; 
    } 

    @Id @GeneratedValue(strategy=IDENTITY)        
    @Column(name="categoryId", unique=true, nullable=false) 
    public Integer getCategoryId() { 
        return this.categoryId; 
    } 

    public void setCategoryId(Integer categoryId) { 
        this.categoryId = categoryId; 
    } 

    @Column(name="categoryName", nullable=false) 
    public String getCategoryName() { 
        return this.categoryName; 
    } 

    public void setCategoryName(String categoryName) { 
        this.categoryName = categoryName; 
    } 
    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="categories") 
    public Set<Computers> getComputerss() { 
        return this.computerss; 
    } 

    public void setComputerss(Set<Computers> computerss) { 
        this.computerss = computerss; 
    } 
    @ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="categories") 
    public Set<Customers> getCustomerss() { 
        return this.customerss; 
    } 

    public void setCustomerses(Set<Customers> customerss) { 
        this.customerss = customerss; 
    } 

If I select values with an HQL query from Computers (I put them in a list) I can see ${computer.computerName}, but none of the ${computer.categories.categoryName} appear. I want each categoryName to be selected by the id. All the categories need to be displayed along with the names. The SQL query for this task wouldn’t be to hard to write, but I want to use Hibernate and I don’t understand it well at the moment. I thought all I need were mappings represented in the classes. Is my simple from Computers wrong for such a selection? I don’t get any errors that would make understanding of what I do wrong a little easier. Any help would be appreciated.

  • 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-31T03:19:42+00:00Added an answer on May 31, 2026 at 3:19 am

    Besides globally configuring the fetch plan of “Computers to Categories” as EAGER using @ManyToOne(fetch=FetchType.EAGER) in the mapping meta-data , you can also keep this relationship as lazy and use fetch join in HQL to eagerly fetch the Categories for a particular use case

      from Computers computer join fetch computer.categories
    

    Then , the Categories of the returned Computers instance will be fully initialized .

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

Sidebar

Related Questions

First of all, I know how to build a Java application. But I have
first of all sorry for the title. I know this is not so clear
First of all I'm sorry for such a question, I look over the internet
First of all, I know that this is because of bad libraries, but I
First of all, I know I asked a similar question before but this one
First of all: I am not an experienced ClearCase user, but I have lots
First of all there is a partial question regarding this, but it is not
First of all, I'm not looking for miracle... I know how PHP works and
First of all, let me clarify that I know you cannot have actual abstract
First of all I agree that mocking external API calls is the right thing

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.