web-dev-qa-db-ja.com

GWT RPCアプリの例外

私は、Eclipse環境を使用してMySQLからデータを挿入および取得するためにGWT RPCおよびHibernateを使用しています。 1つのMySQLテーブルからデータを挿入および取得するために、サービスインターフェイスに2つのメソッドを記述しました。

プログラムは問題なく実行されていますが、この例外が発生しています。

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クラス:

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クラス:

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());
                        }



            }
        });

      }
}
34
enterprize

あなたのコードは正常に動作しているが、この例外がログに表示されていることを意味しますか?例外とは、基本的にコンパイルキャッシュが何らかの理由でロードに失敗したことを意味します。キャッシュが何らかの理由で破損している可能性が高いため、プロジェクトからフォルダーgwt-UnitCacheを削除してみてください。これで問題が解決するはずです。

63
jusio

多分それはエラーメッセージであり、あなたははいをクリックしました: enter image description here

0
user529543