views:

41

answers:

1

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

A: 

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.

Adrian Pirvulescu