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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:33:38+00:00 2026-05-16T03:33:38+00:00

I am trying to learn JPA with Hibernate and binding it to a GUI

  • 0

I am trying to learn JPA with Hibernate and binding it to a GUI built in Netbeans with Beans Binding. It is a application listing dogs. Each dog can have one to many puppies. You can add and delete dogs, and for each dog you can add and delete puppies.

The dogs are displayed in a JList, when the user selects a dog its properties is shown in JTextFileds and its puppies are shown in a JTable. Adding/deleting dogs works fine because the list containing the Dog instances are Observable.

The Dogs puppies are maintained in a Collection in the Dog class with getter and setter:

@OneToMany(targetEntity = Puppie.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "dog_id")
private Collection<Puppie> puppies;

public Collection<Puppie> getPuppies() {
    if (puppies == null) {
        puppies = new ArrayList<Puppie>();
    }
    return puppies;
}

public void setPuppies(Collection<Puppie> puppies) {
    Collection<Puppie> oldPuppies = this.puppies;
    this.puppies = puppies;
    changeSupport.firePropertyChange("puppies", oldPuppies, puppies);
}

When I add a puppie to the dog selected in the JList it is not reflected in the JTable immediately. I have to select another dog and then reselect the dog I added the puppy to to make it show up in the JTable. I am using the following add/delete puppie methods in the Dog class:

public void addPuppie(Puppie puppie) {
    getPuppies().add(puppie);
}

public void deletePuppie(Puppie puppie) {
    getPuppies().remove(puppie);
}

The JTable is bound to the JList (and not the dogs list) with ${selectedElement.puppies} as binding expression.

The setters in the Puppie class fire property changes when properties are set.

This is the code for adding a puppie:

@Action
public void addPuppy() {
    Puppie p = new Puppie();
    p.setName("new puppie");
    entityManager.persist(p);

    int selectedIndex = dogsJList.getSelectedIndex();
    Dog d = (Dog) dogList.get(selectedIndex);
    d.addPuppie(p);
    setSaveNeeded(true);
}

Any help would be greatly appreciated! Let me know if you need more information.

Regards,
Henrik

  • 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-16T03:33:38+00:00Added an answer on May 16, 2026 at 3:33 am

    It seems that the JTable isn’t automatically updated. By looking at the Netbeans generated code it clears the selection in the JList and then reselects the entry, and thereby the JTable get refreshed.

    Since Netbeans generates this code I’m assuming that the second JTable can not be automatically updated with Bean Binding and that one have to clear the selection in the JList and then reselects the entry.

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

Sidebar

Related Questions

I am trying to learn JPA, and Sun tutorial on JPA (order application) is
This week I've been trying to learn Spring, JBoss, Maven, JPA and Hibernate and
I'm trying to learn about grails with Google App Engine and JPA by following
Trying to learn PL/SQL with multimedia data. Can anyone please point out that from
I'm trying to learn JPA and I want create a simple Java command line
I trying to learn web application development. I'm currently using Google App Engine to
While trying to learn the source for GameLibrary sample application I saw a line
Trying to learn Sencha Touch 2 and I can't seem to find out how
Trying to learn a bit about PDO and is going through this tutorial .
Trying to learn about php's arrays today. I have a set of arrays like

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.