Lazy collection problem on back to the server

57 views
Skip to first unread message

Pedro Lucas

unread,
May 10, 2011, 9:48:51 AM5/10/11
to dpHibernate
I have two classes, for example:
Country and FrDepartement.
Each Country has many FrDepartement Lazy mode.
I am using Tomcat 7, BlazeDs4, DpHibernate 2.0 RC6, Spring 3.
When I get all the Country by the method: getCountry.
Returns the list of Country, include each one a list FrDepartement on
lazy mode.
When I send to the Country setCountry method, it returns the error in
Fllex:
"Fault When loading data: flex.messaging.MessageException: Can not
invoke method 'setCountry. " 2 But a sit arguments Were Were expected.
"
And in Java:

After the error it calls the SQL to load all FrDepartaments:
"
INFO org.springframework.flex.servlet.MessageBrokerHandlerAdapter -
Channel endpoint my-amf received request.
{operation})****************loadProxyBatch
{deserialize} 2
Hibernate:
select
this_.id_fr_departement as id1_1_1_,
this_.fk_country as fk3_1_1_,
this_.name_departement as name2_1_1_,
country2_.id_country as id1_0_0_,
country2_.name_country as name2_0_0_
from
addfr.fr_departement this_
left outer join
addfr.country country2_
on this_.fk_country=country2_.id_country
where
this_.id_fr_departement in (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
{invoke} 320
{serialize} 16
"
INFO org.springframework.flex.servlet.MessageBrokerHandlerAdapter -
Channel endpoint my-amf received request.
{operation})****************setCountry
flex.messaging.MessageException: Cannot invoke method 'setCountry'. 2
arguments were sent but 1 were expected.
at
flex.messaging.util.MethodMatcher.methodNotFound(MethodMatcher.java:
394)
at flex.messaging.util.MethodMatcher.getMethod(MethodMatcher.java:
172)
at
flex.messaging.services.remoting.adapters.JavaAdapter.invoke(JavaAdapter.java:
405)
at
org.dphibernate.adapters.RemotingAdapter.superInvoke(RemotingAdapter.java:
73)
at
org.dphibernate.serialization.HibernateDeserializer.invokeLoad(HibernateDeserializer.java:
171)
...
"

Am I missing something?

Robert Brendler

unread,
May 10, 2011, 10:11:47 AM5/10/11
to dphib...@googlegroups.com
Hi Pedro,

I'd say you're passing 2 arguments in your flex code where only one is expected on server side.

When I ran into this error I passed an extra IResponder as additional argument instead of using the returned AsyncToken, maybe it helps.

As far as I understood, please correct me if I am wrong ...
you should use the .save() function on your objects instead of using extra services to persist entities.
# Create a department object,
# set it a new country object (or get an already persisted one via HibernateManaged.defaultHibernateService.loadProxy(key, dummyCountryObject)),
# call .manage() on the newly created objects (department, country),
# call .save on the department

cheers
rob

2011/5/10 Pedro Lucas <pedrolu...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "dpHibernate" group.
To post to this group, send email to dphib...@googlegroups.com.
To unsubscribe from this group, send email to dphibernate...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dphibernate?hl=en.


Pedro Lucas

unread,
May 10, 2011, 10:28:06 AM5/10/11
to dpHibernate
I call a very simple code:
protected function setCountrys():void
{
var token:AsyncToken =
countryService.setCountry(countryDG.selectedItem as Country);
token.addResponder(new
mx.rpc.Responder(resultSetCountry,faultHandler));
}

countryDG is DataDrid with Countrys. Java side:

@RemotingInclude
@Secured("ROLE_USER")
public void setCountry(Country c) {
System.out.println(c.getNameCountry());
}

Can I improve it?
I'll take a look at the save method. but in my original project was
impractical, I need to call the server only once for several updates.
Thank you very much for your attention.

Robert Brendler

unread,
May 10, 2011, 10:51:26 AM5/10/11
to dphib...@googlegroups.com
Your code should work fine like this, is this what is throwing your error?

In terms of improving the .save() method should be the tool of choice. It makes use of the HibernateUpdater and the local change repository. This method works recursively on all referenced objects. Call save() on the root and you're done. It should just commit changes in form of an array of ChangeMessage objects. I suggest you have a closer look at the lazyOverflow example. Check out the current version from the 2.0 branch of the dpHibernate repo. Have a look at the SignInPM and QuestionViewPM. The only thing you should need a separate data access service for is your reading queries, such as getAll or getAllByCountry etc, at least that is what my server setup looks like at the moment.

2011/5/10 Pedro Lucas <pedrolu...@gmail.com>

--

Pedro Lucas

unread,
May 10, 2011, 2:55:34 PM5/10/11
to dpHibernate
Yes, is this what is throwing the error.

He goes to the method invokeLoad in class HibernateDeserializer, when
he tries to read the first of FrDepartaments lazy Collection:

Line 171: Object result =
this.adapter.superInvoke(this.remotingMessage);

This is the debug of first call to the method Translate. See
proxyInitialized that are false. Is this normal?:
obj Arrays$ArrayList<E> (id=5985)
[0] Country (id=5987)
frDepartements ArrayCollection (id=5989)
[0...99]
[0] FrDepartement (id=5993)
country null
idFrDepartement Integer (id=5998)
nameDepartement null
proxyInitialized Boolean (id=166)
value false
[EXCLUDED INFORMATIONS [1...99]]
[100...104]
idCountry Integer (id=5990)
value 1
nameCountry "France" (id=5991)
proxyInitialized Boolean (id=144)
value true

This is the variable sent on line 171 described above:
remotingMessage RemotingMessage (id=6127)
body null
clientId "F09C96AD-0E09-455B-9B74-DF5E536BF9AE" (id=6129)
clientIdBytes null
destination "countryService" (id=6130)
headers HashMap<K,V> (id=6131)
messageId "D09FD7D6-EB85-B373-E2D5-DB3AFB88365D" (id=6133)
messageIdBytes null
operation "setCountry" (id=6134)
parameterList null
parameters Object[2] (id=6136)
[0] Class<T> (com.atlanta.vo.FrDepartement) (id=164)
[1] Integer (id=5998)
value 0
remotePassword null
remoteUsername null
source null
timestamp 1305053166651
timeToLive 0

Tanks

Robert Brendler

unread,
May 11, 2011, 3:02:02 AM5/11/11
to dphib...@googlegroups.com
Hi Pedro,

you're right proxyInitialized should be true from the moment you create the bean instance on the client, even before manage() and save(). I don't have a working sample project I could have a look at right now, so I am afraid I can't be a big help on this one.

From the log I see that setCountry receives 2 parameters: the class FrDepartment and the id of the referenced instance in the Country in the frDepartments list, but not the Country object itself as expected. Also check if your flash cache is emptied and you got the most recent version of your code in your browser.

regarding the save() method ... try this after login to your channelset:

HibernateManaged.defaultHibernateService = dataAccessService; // dataAccessService is a HibernateRemoteObject, with logged in ChannelSet, make sure the dataAccessService is accessible on the server, see lazyOverflow for an example

var country:Country = new Country(); // I assume this is a subclass of HibernateBean as all your bean classes
country.manage();
var dep:FrDepartment = new FrDepartment();
dep.manage();
country.frDepartments.addItem(dep);
country.save();
Reply all
Reply to author
Forward
0 new messages