exception in GWT RPC app
Asked Answered
K

2

34

I am using GWT RPC & Hibernate to insert and retrieve data from MySQL using eclipse environment. I have written two methods in service interfaces to insert & retrieve data from a single MySQL table.

The program is running fine but it is raising this exception.

Exception in thread "UnitCacheLoader" java.lang.RuntimeException: Unable to read from byte cache
    at com.google.gwt.dev.util.DiskCache.transferFromStream(DiskCache.java:166)
    at com.google.gwt.dev.util.DiskCacheToken.readObject(DiskCacheToken.java:87)
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at com.google.gwt.dev.javac.PersistentUnitCache.loadUnitMap(PersistentUnitCache.java:493)
    at com.google.gwt.dev.javac.PersistentUnitCache.access$000(PersistentUnitCache.java:92)
    at com.google.gwt.dev.javac.PersistentUnitCache$UnitCacheMapLoader.run(PersistentUnitCache.java:122)
Caused by: java.io.StreamCorruptedException: unexpected EOF in middle of data block
    at java.io.ObjectInputStream$BlockDataInputStream.refill(Unknown Source)
    at java.io.ObjectInputStream$BlockDataInputStream.read(Unknown Source)
    at java.io.ObjectInputStream.read(Unknown Source)
    at java.io.InputStream.read(Unknown Source)
    at com.google.gwt.dev.util.DiskCache.transferFromStream(DiskCache.java:154)
    ... 16 more

ServiceImpl class:

package rpctest.server;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
//import com.hib.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.Transaction;
import rpctest.shared.User;
import rpctest.client.RpctestService;

public class RpctestServiceImpl extends RemoteServiceServlet  implements RpctestService {

        public String addUser(String name1, String name2)
            throws IllegalArgumentException {

              Transaction trns = null;
              Session session = HibernateUtil.getSessionFactory().openSession();
              try {
               trns = session.beginTransaction();

               User user = new User();

               user.setFirstName(name1);
               user.setLastName(name2);

               session.save(user);

               session.getTransaction().commit();
              } catch (RuntimeException e) {
               if(trns != null){
                trns.rollback();
               }
               e.printStackTrace();
              } finally{
               session.flush();
               session.close();
              }

        return name1+name2; // to test flextable entris only 
    }

    @Override
    public  User[] getUser()
             {

              List<User> getUser = null;

              Transaction trns = null;
              Session session = HibernateUtil.getSessionFactory().openSession();
              try {
               trns = session.beginTransaction();
               getUser = session.createQuery("from User").list();

               //* for (Iterator<User> iter = getUser.iterator(); iter.hasNext();) 
              //{
                //User user = iter.next();
                //
              //*}             

               trns.commit();
              } catch (RuntimeException e) {
               if(trns != null){
                trns.rollback();
               }
               e.printStackTrace();
              } finally{
               session.flush();
               session.close();
             }
              return getUser.toArray(new User[getUser.size()]);
        }
}

entrypoint class:

package rpctest.client;

import java.util.ArrayList;

import rpctest.shared.User;
import rpctest.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Rpctest implements EntryPoint {

    final TextBox firstName = new TextBox();
    final TextBox lastName = new TextBox();
    final Button ans = new Button("Add User");
    //final Label label1 = new Label("First Name");
    //final Label label2 = new Label("Last Name");
    private FlexTable userFlexTable = new FlexTable();
    //final Label errorLabel = new Label();

    private VerticalPanel mainpanel = new VerticalPanel();
    private HorizontalPanel addpanel1 = new HorizontalPanel();
    private HorizontalPanel addpanel2 = new HorizontalPanel();
    private final RpctestServiceAsync calNumbers = GWT
            .create(RpctestService.class);

    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {

        userFlexTable.setText(0, 0, "User ID");
        userFlexTable.setText(0, 1, "First Name");
        userFlexTable.setText(0, 2, "Second Name");
        userFlexTable.setText(0, 3, "Remove");

        //add input boxes to panel
        addpanel1.add(firstName);
        addpanel1.add(lastName);

        firstName.setFocus(true);

        //add input 
        mainpanel.add(userFlexTable);
        mainpanel.add(addpanel1);
        addpanel1.add(ans);

        ans.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                        addStock();                 
            }
        });

        lastName.addKeyPressHandler(new KeyPressHandler() {
              public void onKeyPress(KeyPressEvent event) {
                  if (event.getCharCode() == KeyCodes.KEY_ENTER) {
                      addStock();
                  }
                }
              });

        RootPanel.get().add(mainpanel);
        getUser();
    }

private void addStock(){

        String name1 = firstName.getValue();
        // Stock code must be between 1 and 10 chars that are numbers, letters, or dots.
        /*if (!name1.matches("^[0-9A-Z\\.]{1,10}$")) {
          Window.alert("'" + name1 + "' is not a valid name.");
          firstName.selectAll();
          return;
        }*/
         firstName.setValue("");

        String name2 = lastName.getValue();
        /*if (!name2.matches("^[0-9A-Z\\.]{1,10}$")) {
              Window.alert("'" + name1 + "' is not a valid name.");
              lastName.selectAll();
              return;
            }*/
        lastName.setValue("");
        firstName.setFocus(true);

        calNumbers.addUser(name1,name2,
            new AsyncCallback<String>() {
            public void onFailure(Throwable caught) {
                // Show the RPC error message to the user
                    Window.alert("check your inputs");
                }

            @Override
            public void onSuccess(String result) {
            // TODO Auto-generated method stub
                // Add the user to the table.
              //  int row = userFlexTable.getRowCount();
              //  userFlexTable.setText(row, 1, result);

                getUser();
            }
        });
    }

private void getUser(){

       calNumbers.getUser(new AsyncCallback<User[]>() {
            public void onFailure(Throwable caught) {
                // Show the RPC error message to the user
                    Window.alert("Problem in database connection");
                }

            @Override
            public void onSuccess(User[] result) {
                // TODO Auto-generated method stub
                for(int i = 0; i < result.length; i ++)
                    {
                     //String s = result[i].getFirstName();               
                     int row = userFlexTable.getRowCount();
                     userFlexTable.setText(row, 0, result[i].getId().toString());
                     userFlexTable.setText(row, 1, result[i].getFirstName());
                     userFlexTable.setText(row, 2, result[i].getLastName());
                        }



            }
        });

      }
}
Kirchner answered 15/12, 2011 at 14:17 Comment(4)
re-compile the project and try again..Dib
@Ashok: thank you very much. I had already tried few times but did not work for me at least .....Kirchner
possible duplicate of exception in gwt hibernate programWoad
Also, clean + rebuild did it for meFurriery
L
63

You mean your code works fine but you see this exception in logs? Exception basically means that compilation cache failed to load for some reason. Most likely cache has become corrupted for some reason, so try to remove folder gwt-UnitCache from your project, this should help.

Latricialatrina answered 15/12, 2011 at 20:31 Comment(0)
E
0

Maybe it was a error message and you clicked the Yes: enter image description here

Enthetic answered 27/12, 2012 at 17:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.