Serialize List only first object serialized

29 views
Skip to first unread message

amizon

unread,
Feb 14, 2011, 8:49:40 AM2/14/11
to dpHibernate
Hi

I wonder if you can help, ive been trying out the 2.0 version of
dpHibernate, its looking great and all hooked up and working. However
Im having real difficulties in transferring an ArrayList from a
service to Flex. It seems like only the first object in the List is
serialized.

Take a look

[0] = (Typed Object #3 'com.saviso.rad.minerva.domain.Platformuser')
uid = "7df2b56c-6cd5-4d30-8c8c-93856beadbdd"
enabled = true
lastname = null
firstname = null
accountNonExpired = true
proxyKey = null
password = "21232f297a57a5a743894a0e4a801fc3"
proxyInitialized = true
id = 196.0
username = "admin"
archived = false
authorities = (Array #4)
[0] = (Typed Object #5
'com.saviso.rad.minerva.domain.Platformrole')
id = 24.0
uid = "369276a7-3fc1-4685-83cf-031bd469f86f"
authority = "ROLE_ADMIN"
archived = false
roleName = "ROLE_ADMIN"
proxyKey = null
proxyInitialized = true
[1] = (Typed Object #6
'com.saviso.rad.minerva.domain.Platformrole')
id = 25.0
uid = "13301ad1-0a9b-4c3b-98fa-813fbe8c3e64"
authority = "ROLE_USER"
archived = false
roleName = "ROLE_USER"
proxyKey = null
proxyInitialized = true
email = null
roles = (Externalizable Object #7
'flex.messaging.io.ArrayCollection')
(Array #8)
[0] = (Ref #5)
[1] = (Ref #6)
credentialsNonExpired = true
accountNonLocked = true
[1] = (Typed Object #9
'com.saviso.rad.minerva.domain.Platformuser')
uid = "efbd5d04-7ed0-4d76-803e-feb6dbc4703e"
proxyKey = null
proxyInitialized = false
[2] = (Typed Object #10
'com.saviso.rad.minerva.domain.Platformuser')
uid = "c0db8639-0635-433b-be41-095902cc21de"
proxyKey = null
proxyInitialized = false


Any ideas what is going on. I cant figure it out.

Thanks for the help

Anthony

Marty Pitt

unread,
Feb 14, 2011, 9:09:00 AM2/14/11
to dphib...@googlegroups.com
Hi

I notice that proxyKey is null. Have you implemented the proxy
interface correctly? Normally the getter for proxyKey should return
The entities primary key.

Another common gotcha with collections is to e sure that the class
within the collection is referenced somewhere in your application.

If not, the class is compiled into the swf, and the collection members
arrive on the client as Object, instead of the correct type.

This breaks serialization.

Hope tha helps

Marty
Sent from my iPhone

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

amizon

unread,
Feb 14, 2011, 9:48:35 AM2/14/11
to dpHibernate
Hi Marty

Thanks for the two pointers.

Yeah the class is referenced in the app .. i must have messed up the
proxy interface then. This is actually an attempt at upgrading an
application from 1.x dpHibernate to the 2.0 release candidate to check
out Probably easier to start a fresh!

On Feb 14, 2:09 pm, Marty Pitt <martyp...@me.com> wrote:
> Hi
>
> I notice that proxyKey is null.  Have you implemented the proxy  
> interface correctly?  Normally the getter for proxyKey should return  
> The entities primary key.
>
> Another common gotcha with collections is to e sure that the class  
> within the collection is referenced somewhere in your application.
>
> If not, the class is compiled into the swf, and the collection members  
> arrive on the client as Object, instead of the correct type.
>
> This breaks serialization.
>
> Hope tha helps
>
> Marty
> Sent from my iPhone
>

Nicolas Beaudrot

unread,
Feb 14, 2011, 11:35:05 AM2/14/11
to dpHibernate
I have exactly the same problem.

Have you found a solution ?

I think it could be linked to [Managed] metadata. When I use java
debugger, I can see that the list is correct.
proxyInitialised=true,...
But when I print the value on the flex side, only the first object is
not null.
All the other objects have the property proxyInitialised=false and
values equals to null.

I don't understand why, because for this case I'm not using a
dpHibernate destination. I'm using a simple RemoteObject.
Is it possible to use both RemoteObject and HibernateRemoteObject ?

Thanks.

Umut

unread,
Feb 15, 2011, 6:37:01 AM2/15/11
to dpHibernate
I have similar problem,

When I used a service returning an array of entities, only the first
entity is initialized, the rest of the collection consists of proxies
(Their proxyKeys are not null). This behaviour is independent from the
pageSize setting in the xml. I tried every combination with that
setting but couldn't manage to get a fully initialized collection. I
don't know if this is a bug or I am missing something. I'd also
appreciate any help on this.

P.S. Nicolas, about using non-dpHibernate remote object; when you use
a non-dpHibernate remote object it won't lazy load, instead you'll get
a full tree of objects. Other than that yes it is technically possible
to use them together.

Nicolas Beaudrot

unread,
Feb 15, 2011, 7:04:01 AM2/15/11
to dpHibernate
@Umut Ok thanks for the answer.
But, when I use a RemoteObject to get an array of entities, I have
similar problem. Only the first entity is initialized.
It's weird because before I integrate dpHibernate to the project,
everythink were working fine.

I think I missed something in config files.

Marty Pitt

unread,
Feb 15, 2011, 8:11:39 AM2/15/11
to dphib...@googlegroups.com
Hi

Do you see any warnings or errors in the console?

Note - we use the Logging framework, as opposed to trace() so you might need
to activate it -- call this on startup:

Log.addTarget( new TraceTarget() );

That'll make sure our log messages get traced out.

--------------------------------------------------
From: "Nicolas Beaudrot" <gal...@gmail.com>
Sent: Tuesday, February 15, 2011 7:04 AM
To: "dpHibernate" <dphib...@googlegroups.com>
Subject: Re: Serialize List only first object serialized

Marty Pitt

unread,
Feb 15, 2011, 9:36:37 AM2/15/11
to dphib...@googlegroups.com
A couple of other things to check for if only 1 row is being returned:
  • Make sure both the Java class and the Actionscript entity class implement IHibernateProxy.  You can either do this manually, or by subclassing HibernateBean (I reccomend the former)
  • Make sure the service on the BlazeDS side exposes appropriate load methods.  The easiest way to do this is to subclass LazyLoadService or SpringLazyLoadService (depending on your environment)
HTH
 
Marty




--------------------------------------------------
From: "Marty Pitt" <mart...@me.com>
Sent: Tuesday, February 15, 2011 8:11 AM
To: <dphib...@googlegroups.com>

Nicolas Beaudrot

unread,
Feb 15, 2011, 9:47:27 AM2/15/11
to dphib...@googlegroups.com
Thanks Marty for the response. But all entities implement IHibernateProxy. And I have a bean SpringLazyLoadService.

This is my app-config.xml : http://pastebin.com/2ezNu46m

I added a new TraceTarget, but the console does'nt display errors or warnings.

When i run the flex application in debug mode, I got some errors :
Something bad happend
java.lang.NoClassDefFoundError : com/google/common/collect/ArrayListMultimap
Fault when trying to load paged collection data - java.lang.NoClassDefFoundError : com/google/common/collect/ArrayListMultimap

But, I don't use ArrayListMultimap, I'm using ArrayCollection. It's strange.

For each objects in the list, proxyKeys is not null, but proxyInitialized = false.

I don't know what to do :)

Nicolas Beaudrot

unread,
Feb 16, 2011, 4:17:32 AM2/16/11
to dphib...@googlegroups.com
Ok, I found somethink :)

On my java class BaseEntity, I have to add @Transient to the method getProxyKey, if I don't do that, I got an error when I start Tomcat:

@Transient
    public Object getProxyKey(){
        return this.id;
    }

    public void setProxyKey(final Object obj){
        throw new RuntimeException("ProxyKey is read only!");
    }

    @Transient
    public Boolean getProxyInitialized(){
        return proxyInitialized;
    }

    public void setProxyInitialized(final Boolean b){
        proxyInitialized = b;
    }
Error :
... nested exception is org.springframework.beans.factory.nested exception is org.hibernate.MappingException: property mapping has wrong number of columns: fr.schneider.lancid.model.Code.proxyKey type: object

Is it normal ?
--
Nicolas Beaudrot
Département GI -  UTBM
Tél: (+33)6 03 66 33 63
http://www.nicolas-beaudrot.fr


Umut

unread,
Feb 16, 2011, 9:40:46 AM2/16/11
to dpHibernate
I dont use @transient with proxyKey and t works fine. That being said
my BaseEntity looks different than yours.

check lazyoverflow example here
http://code.google.com/p/dphibernate/source/browse/trunk/samples/lazyLoadingWithSpring/java/src/com/mangofactory/pepper/model/BaseEntity.java

And about the error you mentioned earlier;
java.lang.NoClassDefFoundError : com/google/common/collect/
ArrayListMultimap
Fault when trying to load paged collection data -

this error might be because you haven't included some jar files
needed. Again look at the lazyoverflow example to see what is needed
to be in your classpath.

On 16 Şubat, 11:17, Nicolas Beaudrot <nicolas.beaud...@gmail.com>
wrote:

Nicolas Beaudrot

unread,
Feb 16, 2011, 10:06:02 AM2/16/11
to dphib...@googlegroups.com
I don't understand, how it could work without @Transient keyword, because Hibernate will try to map it.

Thanks for the link Umut, but I have already read this code.
Do you still have the bug ?

It's strange, because I'm having the bug even when I use RemoteObject. Only the first one is initialized in flex side.
Maybe it's because of my java services. It doesn't extend SpringLazyLoadService
And if I use the annotation @Service, do I have to create a bean in a config file ?

Thanks for your help.

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

Marty Pitt

unread,
Feb 16, 2011, 10:06:43 AM2/16/11
to dphib...@googlegroups.com
It really depends on how your Hibernate env is configured.  But, yes, if you're using annotated getters/setters, then the proxyKey would need to be transient, as it doesn't exist in your db schema.
 
(Note, the same is true for proxyInitialized)
 
In the example you posted from the springs sample, I'm mapping based on field, not on accessor.  You'll note that proxyInitialized is transient (to prevent hibernate to try mapping it), and that the accessors for proxyKey just return the primary key.
 
HTH
 
Marty
 
 

Sent: Wednesday, February 16, 2011 4:17 AM
Subject: Re: Serialize List only first object serialized

Marty Pitt

unread,
Feb 16, 2011, 10:09:30 AM2/16/11
to dphib...@googlegroups.com
If your service doesn't extend SpringLazyLoadService, you're required to manage the lazy loading yourself.
 
Take a look at these samples for an idea of how to it:
 
Marty

Sent: Wednesday, February 16, 2011 10:06 AM
Subject: Re: Serialize List only first object serialized

Marty Pitt

unread,
Feb 16, 2011, 10:12:04 AM2/16/11
to dphib...@googlegroups.com
 
It really depends on how your Hibernate env is configured.  But, yes, if you're using annotated getters/setters, then the proxyKey would need to be transient, as it doesn't exist in your db schema.
 
(Note, the same is true for proxyInitialized)
 
In the example you posted from the springs sample, I'm mapping based on field, not on accessor.  You'll note that proxyInitialized is transient (to prevent hibernate to try mapping it), and that the accessors for proxyKey just return the primary key.
 
HTH
 
Marty
 
 

Sent: Wednesday, February 16, 2011 4:17 AM
Subject: Re: Serialize List only first object serialized

Ok, I found somethink :)

On my java class BaseEntity, I have to add @Transient to the method getProxyKey, if I don't do that, I got an error when I start Tomcat:

@Transient
    public Object getProxyKey(){
        return this.id;
    }

    public void setProxyKey(final Object obj){
        throw new RuntimeException("ProxyKey is read only!");
    }

    @Transient
    public Boolean getProxyInitialized(){
        return proxyInitialized;
    }

    public void setProxyInitialized(final Boolean b){
        proxyInitialized = b;
    }
Error :
... nested exception is org.springframework.beans.factory.nested exception is org.hibernate.MappingException: property mapping has wrong number of columns: fr.schneider.lancid.model.Code.proxyKey type: object

Is it normal ?

On Tue, Feb 15, 2011 at 3:47 PM, Nicolas Beaudrot <nicolas....@gmail.com> wrote:
Thanks Marty for the response. But all entities implement IHibernateProxy. And I have a bean SpringLazyLoadService.

This is my app-config.xml : http://pastebin.com/2ezNu46m

I added a new TraceTarget, but the console does'nt display errors or warnings.

When i run the flex application in debug mode, I got some errors :
Something bad happend
java.lang.NoClassDefFoundError : com/google/common/collect/ArrayListMultimap
Fault when trying to load paged collection data - java.lang.NoClassDefFoundError : com/google/common/collect/ArrayListMultimap

But, I don't use ArrayListMultimap, I'm using ArrayCollection. It's strange.

For each objects in the list, proxyKeys is not null, but proxyInitialized = false.

I don't know what to do :)




--
Nicolas Beaudrot
Département GI -  UTBM

Nicolas Beaudrot

unread,
Feb 16, 2011, 11:41:08 AM2/16/11
to dphib...@googlegroups.com
@Umut Do you manage the lazy loading yourself or do you use SpringLazyLoadService ?

Thanks Marty for your answer, I think I'm close to make it work :)

Have you got a jar with the source, I want to add breakpoint in your HibernateDeserializer class.

When the java service returns the list, all objects are instanciate and have correct attribute. Then, in the flex code only the first is instanciate. If my java service doesn't manage correctly lazy loading, it could be the problem ?

Thanks in advance for your answer

Marty Pitt

unread,
Feb 16, 2011, 12:21:31 PM2/16/11
to dphib...@googlegroups.com
Jars with source are available in the dist zip.
Also, you can check out the source from the google code site.
 
Yes - if your service doesn't manage lazy loading, that's the problem.

Umut

unread,
Feb 16, 2011, 4:07:58 PM2/16/11
to dpHibernate
I use SpringDataAccessService which is a dphibernate lazy load service
plus it can do stuff like entity sae etc. In other words I don't
manage lazy loading myself no.



On 16 Şubat, 19:21, Marty Pitt <martyp...@me.com> wrote:
> ?Jars with source are available in the dist zip.
> Also, you can check out the source from the google code site.
>
> Yes - if your service doesn't manage lazy loading, that's the problem.
>
> From: Nicolas Beaudrot
> Sent: Wednesday, February 16, 2011 11:41 AM
> To: dphib...@googlegroups.com
> Subject: Re: Serialize List only first object serialized
>
> @Umut Do you manage the lazy loading yourself or do you use SpringLazyLoadService ?
>
> Thanks Marty for your answer, I think I'm close to make it work :)
>
> Have you got a jar with the source, I want to add breakpoint in your HibernateDeserializer class.
>
> When the java service returns the list, all objects are instanciate and have correct attribute. Then, in the flex code only the first is instanciate. If my java service doesn't manage correctly lazy loading, it could be the problem ?
>
> Thanks in advance for your answer
>
>   On Tue, Feb 15, 2011 at 3:47 PM, Nicolas Beaudrot <nicolas.beaud...@gmail.com> wrote:
>
>     Thanks Marty for the response. But all entities implement IHibernateProxy. And I have a bean SpringLazyLoadService.
>
>     This is my app-config.xml :http://pastebin.com/2ezNu46m
>
>     I added a new TraceTarget, but the console does'nt display errors or warnings.
>
>     When i run the flex application in debug mode, I got some errors :
>     Something bad happend
>     java.lang.NoClassDefFoundError : com/google/common/collect/ArrayListMultimap
>     Fault when trying to load paged collection data - java.lang.NoClassDefFoundError : com/google/common/collect/ArrayListMultimap
>
>     But, I don't use ArrayListMultimap, I'm using ArrayCollection. It's strange.
>
>     For each objects in the list, proxyKeys is not null, but proxyInitialized = false.
>
>     I don't know what to do :)
>
>   --
>   Nicolas Beaudrot
>   Département GI -  UTBM
>
>   Tél: (+33)6 03 66 33 63
>  http://www.nicolas-beaudrot.fr
>
>   --
>   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 athttp://groups.google.com/group/dphibernate?hl=en.
>
>   --
>   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 athttp://groups.google.com/group/dphibernate?hl=en.
>
> --
> Nicolas Beaudrot
> Département GI -  UTBM
> Tél: (+33)6 03 66 33 63http://www.nicolas-beaudrot.fr

Nicolas Beaudrot

unread,
Feb 17, 2011, 5:42:49 AM2/17/11
to dphib...@googlegroups.com
I have implemented  IProxyUpdateService, IProxyLoadService, IProxyBatchLoader and I added these methods to my serviceBase, and I still have the problem. And none of these methods are called.
I don't understand why.

    public Set<ObjectChangeResult> saveBean(List<ObjectChangeMessage> objectChangeMessage){
        return proxyUpdaterService.saveBean(objectChangeMessage);
    }

    public Set<ObjectChangeResult> saveBean(ObjectChangeMessage objectChangeMessage){
        return proxyUpdaterService.saveBean(objectChangeMessage);
    }

    public Object loadBean(Class daoClass, Serializable id){
        return proxyLoadService.loadBean(daoClass, id);
    }

    public Map<String, Object> loadProperties(Class<?> daoClass, Serializable id){
        return proxyLoadService.loadProperties(daoClass, id);
    }

    public List<ProxyLoadResult> loadProxyBatch(ProxyLoadRequest[] requests){
        return proxyBatchLoader.loadProxyBatch(requests);
    }

For more options, visit this group at http://groups.google.com/group/dphibernate?hl=en.

Umut

unread,
Feb 17, 2011, 5:56:07 AM2/17/11
to dpHibernate
What you need to implement is one of SpringLazyLoadService or
SpringDataAccessService I guess, I use the letter and it works fine.

On 17 Şubat, 12:42, Nicolas Beaudrot <nicolas.beaud...@gmail.com>
wrote:

Nicolas Beaudrot

unread,
Feb 17, 2011, 8:12:28 AM2/17/11
to dphib...@googlegroups.com
I use the new version of dpHibernate(RC4), and the problem is solved. My objects are correctly instantiated.
I don't understand what was the problem, but finally it's working.

Thank you for your help and for this project.
It's a really good work

Regards,
Nicolas
Reply all
Reply to author
Forward
0 new messages