错误 [TRACE] [rpctest] - 查找入口点类:使用 GWT 使用 Hibernate 将数据插入 MySql
Posted
技术标签:
【中文标题】错误 [TRACE] [rpctest] - 查找入口点类:使用 GWT 使用 Hibernate 将数据插入 MySql【英文标题】:ERRORS [TRACE] [rpctest] - Finding entry point classes: using GWT to insert data into MySql using Hibernate 【发布时间】:2011-12-13 17:07:30 【问题描述】:我正在使用 GWT RPC 和 Hibernate 使用 Eclipse 环境从 mysql 插入和检索数据。我在服务接口中编写了两种方法来从 MySql 中插入和检索数据。
当我实现插入数据的方法时程序运行良好,但当我开始实现从 MySql 检索数据的方法时出现错误。
项目名称是 rpctest 和包名称相同。
这里的项目结构:
rpctest
src
-hibernate.cfg.xml
-user.hbm.xml
-rpctest
-> Rpctest.gwt.xml
-rpctest.client
-> Rpctest.java
-> RpctestService.java
-> RpctestServiceAsync.java
-rpctest.server
-> HibernateUtil.java
-> RpctestServiceImpl.java
-rpctest.shared
-> FieldVerifier.java
-> User.java
这是堆栈跟踪:
[TRACE] [rpctest] - Finding entry point classes
[ERROR] [rpctest] - Unable to find type 'rpctest.client.Rpctest'
[ERROR] [rpctest] - Hint: Previous compiler errors may have made this type unavailable
[ERROR] [rpctest] - Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
[ERROR] [rpctest] - Failed to load module 'rpctest' from user agent 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)' at 127.0.0.1:51539
Rpctest.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='rpctest'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='rpctest.client.Rpctest'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
服务接口
package rpctest.client;
import java.util.ArrayList;
import rpctest.shared.User;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("testService")
public interface RpctestService extends RemoteService
public String addUser(String firstName,String lastName) throws IllegalArgumentException;
public User[] getUser();
-------
package rpctest.client;
import java.util.ArrayList;
import rpctest.shared.User;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface RpctestServiceAsync
void addUser(String firstName, String lastName,
AsyncCallback<String> callback);
void getUser(AsyncCallback<User[]> asyncCallback);
Rpctest.java
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);
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);
);
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
Window.alert("i m in getUser!");
);
RpctestServiceImpl.java
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()]);
【问题讨论】:
【参考方案1】:源元素看起来很可疑,如果您尝试使用:<source path='rpctest/client'/>
和 <source path='hibDomain'/>
会发生什么?
<source path='server'/>
肯定是错的,你不希望你的服务器端代码 gwt 被编译。
【讨论】:
我删除了服务器,并编辑了其他路径变量。它现在引发了更多错误。我编辑了 OP。 使用 'rpctest/client' 与 OP 有相同的错误,即在编辑之前 是的,这绝对是代码组织。请尽量按照推荐的项目布局(服务器、客户端和共享包在同一级别,只有客户端和共享暴露给GWT):code.google.com/webtoolkit/doc/latest/… 我编辑了代码。删除 hibDomain 文件夹并将 User.java 移动到共享文件夹。现在客户端和共享都暴露给 GWT。我编辑了帖子,请看。错误现在是“找不到入口点类”。 源路径又错了,应该是而不是以上是关于错误 [TRACE] [rpctest] - 查找入口点类:使用 GWT 使用 Hibernate 将数据插入 MySql的主要内容,如果未能解决你的问题,请参考以下文章