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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:41:58+00:00 2026-05-20T09:41:58+00:00

I had recently posted someone about populating a JTable, which is now fully functional.

  • 0

I had recently posted someone about populating a JTable, which is now fully functional.
How ever, I am stuck over something else now, I’m hoping to achieve two specific thigns with this thread.

One is to solve my problem, and the other is to have an answer ready for when others stumble across the same problem, cause I never found a proper answer to this yet.

I have the following scenario

Two tables:

games
id pk int
genre int
title varchar ….

genre
id pk int
name varchar ..

One game can only have one genre, but one genre can contain many games.

I’m using Eclipse as my IDE and eclipselink as my JPA provider.

I have generated the classes with the entity wizard provided by eclipse, whom also allowed me to define relationships between the two tables.

The relationships look as follows:

@Entity
@Table(name="games")
public class Game implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name="Id", unique=true, nullable=false)
private int id;

@Temporal( TemporalType.DATE)
@Column(name="AddDate", nullable=false)
private Date addDate;

@Lob()
@Column(name="Description", nullable=false)
private String description;

@Temporal( TemporalType.DATE)
@Column(name="ModifiedDate", nullable=false)
private Date modifiedDate;

@Temporal( TemporalType.DATE)
@Column(name="ReleaseDate", nullable=false)
private Date releaseDate;

@Column(name="Title", nullable=false, length=255)
private String title;

//bi-directional many-to-one association to Genre
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="Genre", nullable=false)
private Genre genreBean;

//bi-directional many-to-one association to Publisher
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="Publisher", nullable=false)
private Publisher publisherBean;

and the genre

@Entity
@Table(name="genres")
public class Genre implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name="Id", unique=true, nullable=false)
private int id;

@Column(name="Genre", nullable=false, length=150)
private String genre;

//bi-directional many-to-one association to Game
@OneToMany(mappedBy="genreBean")
private List<Game> games;

I use the following to select all games

        List<Game> games;

    try{
        TypedQuery<Game> selectGamesQuery = entityManager.createQuery("SELECT g FROM Game g", Game.class);
        games = selectGamesQuery.getResultList();
    } catch(Exception e) {
        games = null;
        System.out.println(e);

The problem here is, List games does not contain the genre name, actually, it is empty.

How do I configure the list to contain a game that has the following attributes: id, title, genre-name, publisher-name, releasedate

In my JTable I have tried the following:

        switch(columnIndex){
        case 0:
            return game.getTitle();
        case 1:
            return game.getPublisherBean().getPublisher();
        case 2:
            return game.getGenreBean().getGenre();
        case 3:
            return game.getReleaseDate();
    }

In this case, in my JTable the columns for case 1 and 2 are empty, while the rest works.

So my table content looks like

Battlefield 3 empty empty 3-3-2011

I think with this I should have provided enough info.

Please let me know if there is any mistake or error in the code, or perhaps the select query, as I couldn’t even find if I HAVE to write an explicit JOIN query and that it doesnt do that due to the defined relationship.

I’m still a noobie, so please be gentle ^^

Thank you for your time.

  • 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-20T09:41:59+00:00Added an answer on May 20, 2026 at 9:41 am

    to get a bit closer to the problem you could enable finegrained JPA logging by adding the following in your persistence.xml (inside a persistence-unit element):

    <properties>
          <property name="eclipselink.logging.level" value="FINEST"/>
    </properties>
    

    Then watch your log file and look how the jpql-query gets translated to sql.

    Another idea (may sound stupid!): Did you set the foreign key constraints in the database too or only in Persistence Unit?

    Hope this helps

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

Sidebar

Related Questions

We recently had a new requirement to use the phonon component of Qt, which
In searching for an answer to an interesting situation which I had recently encountered
I had recently starting learning openGLES and right now I had gone through some
Recently, someone asked about an algorithm for reversing a string in place in C
This is one of an interview question which I had recently. I would like
Until recently, I posted Python code (whitespace matters) to blogspot.com using something like this:
I had recently a problem with oom-killer starting to kill processes after some time.
I had recently (and unfortunately) uninstalled the google chrome browser from my computer -while
I recently had a need to interpret a DEC 32-bit floating point representation. It
I recently had to work on a project where the previous developer modified the

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.