Flex+JPA/Hibernate+BlazeDS+MySQL 如何调试这个怪物?

发布于 2024-09-05 14:46:48 字数 2504 浏览 6 评论 0原文

好的,我正在使用该主题中的技术制作一个“简单”的网络应用程序,最近我发现 http://www.adobe.com/devnet/flex/articles/flex_hibernate.html 所以我正在关注它并尝试将其应用到我的应用程序中,唯一的区别是我在 Mac 上工作,我使用 MAMP 作为数据库(所以对我来说没有命令行)。

问题是我在检索/连接数据库时遇到一些问题。

我有 remoting-config.xml、persistance.xml、News.java 类(我的实体)、NewsService.java 类、News.as 类 - 所有这些都与教程中一样。当然,我的 .mxml 之一中有这一行:

<mx:RemoteObject id="loaderService" destination="newsService" result="handleLoadResult(event)" fault="handleFault(event)" showBusyCursor="true" />

我的 remoting-config.xml 看起来像这样(其中一部分):

<destination id="newsService">

    <properties><source>com.gamelist.news.NewsService</source></properties>

</destination>

NewsService 有一个方法:

    public List<News> getLatestNews() {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
    EntityManager em = emf.createEntityManager();
    Query findLatestQuery = em.createNamedQuery("news.findLatest");
    List<News> news = findLatestQuery.getResultList();
    return news;
}

命名查询位于 News 类中:

@Entity
@Table(name="GLT_NEWS")
@NamedQueries({
@NamedQuery(name="news.findLatest", query="from GLT_NEWS order by new_date_added limit 5 ") 
})

HandlingLoadResult 看起来像这样:

    private function handleLoadResult(ev:ResultEvent):void {
        newsList = ev.result as ArrayCollection;
        newsRecords = newsList.length;
    }

哪里:

[Bindable]
private var newsList:ArrayCollection = new ArrayCollection();

但是当我尝试触发时:

loaderService.getLatestNews();

什么也没发生,newsList 是空的。

我需要指出几点: 1)正如我所说,我没有手动安装mysql,但我正在使用MAMP(是的,服务器正在运行),这会引起一些麻烦吗? 2)我已经有一个“gladm”数据库,并且有一个包含所有字段的“GLT_NEWS”表,这很糟糕吗?

基本上问题是我该如何调试这个东西以便我可以找到我所犯的错误?我知道 loadData() 已执行(执行了 Trace()),但我不知道 loaderService.getLatestNews() 会发生什么...

@编辑:好的,所以我看到我在“故障处理程序”中收到错误“

"Error: Client.Error.MessageSend - Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 404: url: 'http://localhost:8080/WebContent/messagebroker/amf' - "

@EDIT2:好吧,我解决了这个问题,因为事实证明我的 ContextRoot 不正确,有趣的是我无法通过转到项目属性 -> Flex Server 来编辑它,因为它是不可编辑的!我必须找到 .flexProject 文件并对其进行编辑(显然我的 Flex Navigator 没有显示它,并且偶然我注意到它被过滤了)。

Ok so I'm making a "simple" web app using the technologies from the topic, recently I found http://www.adobe.com/devnet/flex/articles/flex_hibernate.html so I'm following it and I try to apply it to my app, the only difference being I'm working on a Mac and I'm using MAMP for the database (so no command line for me).

The thing is I'm having some trouble with retrieving/connecting to the database.

I have the remoting-config.xml, persistance.xml, a News.java class (my Entity), a NewsService.java class, a News.as class - all just like in the tutorial. I have of course this line in one of my .mxmls:

<mx:RemoteObject id="loaderService" destination="newsService" result="handleLoadResult(event)" fault="handleFault(event)" showBusyCursor="true" />

And my remoting-config.xml looks like this (well part of it):

<destination id="newsService">

    <properties><source>com.gamelist.news.NewsService</source></properties>

</destination>

NewsService has a method:

    public List<News> getLatestNews() {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
    EntityManager em = emf.createEntityManager();
    Query findLatestQuery = em.createNamedQuery("news.findLatest");
    List<News> news = findLatestQuery.getResultList();
    return news;
}

And the named query is in the News class:

@Entity
@Table(name="GLT_NEWS")
@NamedQueries({
@NamedQuery(name="news.findLatest", query="from GLT_NEWS order by new_date_added limit 5 ") 
})

The handledLoadResult looks like this:

    private function handleLoadResult(ev:ResultEvent):void {
        newsList = ev.result as ArrayCollection;
        newsRecords = newsList.length;
    }

Where:

[Bindable]
private var newsList:ArrayCollection = new ArrayCollection();

But when I try to trigger:

loaderService.getLatestNews();

nothing happens, newsList is empty.

Few things I need to point out:
1) as I said I didn't install mysql manually, but I'm using MAMP (yes, the server's running), could this cause some trouble?
2) I already have a "gladm" database and I have a "GLT_NEWS" table with all the fields, is this bad?

Basically the question is how am I suppose to debug this thing so I can find the mistake I'm making? I know that loadData() is executed (did a trace()), but I have no idea what happens with loaderService.getLatestNews()...

@EDIT: ok so I see I'm getting an error in the "fault handler" which says

"Error: Client.Error.MessageSend - Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 404: url: 'http://localhost:8080/WebContent/messagebroker/amf' - "

@EDIT2: Ok i solved the problem, as it turns out my ContextRoot was incorrect, the funny thing is I couldn't edit it by going to Project properties->Flex Server as it was uneditable! I had to find the .flexProject file and edit it (obviously my Flex Navigator didn't show it and by accident I noticed it was being filtered).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝礼 2024-09-12 14:46:48

为了回答你关于调试这个怪物的问题......这就是我所做的。

  1. 在我的 Java 代码中设置断点

  2. 使用适当的调试 JVM 属性集启动 Java 应用程序服务器(例如 -Xdebug -Xrunjdwp:transport=dt_socket ,address=8000,server=y,suspend=n)

  3. 在 Eclipse 中,我将远程调试器附加到默认端口 8000 上的应用程序服务器。当遇到断点时,Java 调试器将打开。

  4. 在我的 Flex 应用程序(或其模块之一)中设置断点。

  5. 从 Eclipse(使用 Flash Builder)我启动了 Flex 应用程序的调试配置。当遇到断点时,Flex 调试器将打开。

此时我打开了两个调试器,一切正常。我做的另外两件事:

a)延长交易系统超时,这样当我坐在那里思考几分钟时它就不会被触发

b)在客户端和服务器之间使用 Charles 代理(在反向代理模式下)来观看AMF 流量和查看有效负载等。

希望这会有所帮助。

To answer your question as to, in general, debug this monster...here is what I do.

  1. Set break points in my Java code

  2. Start up the Java application server with the appropriate debug JVM properties set (e.g. -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n)

  3. From Eclipse, I attach a remote debugger to the app server on the default port 8000. The Java Debugger will open up when a break point is hit.

  4. Set breakpoints in my Flex application (or one of its modules).

  5. From Eclipse (with Flash Builder) I launch a debug configuration for my Flex app. The Flex Debugger will open up when a break point is hit.

At this point I have two debuggers open and everything work great. Two other things I do:

a) extend the transaction system timeout, so it doesn't get trigger while I am sitting there think for a few minutes

b) use Charles Proxy (in reverse proxy mode) inbetween the client and server to watch the AMF traffic and view payloads, etc.

Hope this helps.

杀手六號 2024-09-12 14:46:48

您的错误意味着您没有以正确的方式调用服务器。 web.config 文件或其他 BlazeDS 配置文件的 url 出现问题。

your error means you are not calling the server on the right way. Something is wrong there, the url the web.config file or other BlazeDS config files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文