Mateusz Dymczyk
Mateusz Dymczyk

Reputation: 15141

Flex+JPA/Hibernate+BlazeDS+MySQL how to debug this monster?

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).

Upvotes: 3

Views: 874

Answers (2)

Dave
Dave

Reputation: 21924

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.

Upvotes: 3

Adrian Pirvulescu
Adrian Pirvulescu

Reputation: 4340

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.

Upvotes: 0

Related Questions