Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: JTable refresh with Hibernate

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JTable refresh with Hibernate

    I've been searching and trying for hours now, still can't find a solution that should be obvious. This is my first post, so please be kind.

    Using NetBeans 6.9.1, I've created a JTable and drag&dropped a Hibernate MySQL database table onto it. This works well, and fills the JTable with the column headers and rows. I can successfully add rows to the database, but the table is not updated. Looking at the code created by the IDE for a generic desktop database app, I came up with the following code, which seems like it should work, but does not.

        private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {
            tournamentmarshalPUEntityManager.getTransaction().begin();
            java.util.Collection data = tournamentQuery.getResultList();
            for (Object entity : data) {
                tournamentmarshalPUEntityManager.refresh(entity);
            }
            tournamentList.clear();
            tournamentList.addAll(data);
            tournamentmarshalPUEntityManager.getTransaction().commit();
            System.out.println("refreshing");
        }

    Do I need to be thinking about firePropertyChange() to solve this?

    I've seen this question asked online many different ways, and nobody had written a clear concise answer as yet. Thanks in advance for your thoughtful, considered answers!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JTable refresh with Hibernate

    Is the model of you table based upon the tournamentList variable? Once you add items to the table model, you should fire the model's data changed function to notify all listeners...assuming the model is or extends off AbstractTableModel:
    ((AbstractTableModel)table.getModel()).fireTableDataChanged();
    You can also call repaint() on the table, but this won't fire any table model listeners you have registered.
    Last edited by copeg; September 22nd, 2010 at 11:27 AM.

  3. #3
    Member
    Join Date
    Oct 2010
    Posts
    40
    Thanks
    0
    Thanked 2 Times in 1 Post

    Default Re: JTable refresh with Hibernate

    did u check the added rows in the database? are they really there? hibernate have some caches and the application gets the data there, not directly from the database. it seems your hibernate session is not synchronized with your database. did you try flushing the session after the query? it would help if you can post your hibernate configuration file.

Similar Threads

  1. GUI - refresh problem
    By Shnkc in forum AWT / Java Swing
    Replies: 5
    Last Post: April 2nd, 2010, 06:11 AM
  2. Hibernate Concepts
    By systech44 in forum Web Frameworks
    Replies: 2
    Last Post: March 12th, 2010, 07:32 AM
  3. Replies: 0
    Last Post: March 2nd, 2010, 07:57 AM
  4. doubt in hibernate
    By jyothishey in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 10th, 2010, 11:43 PM
  5. Recommendations for E commerce web application
    By Desert Fox in forum Web Frameworks
    Replies: 2
    Last Post: November 1st, 2009, 12:31 AM

Tags for this Thread