Re: OpenJPA Date Proxy serialization problem when using entities with GWT

2011-04-04 Thread Prashant Bhat
Hi Pinaki,

The opentrader domain entities do not use j.u.Date fields. But as in the
above provided sample application, GWT serialization exception is thrown if
the entity being serialized has a Date field.

Regards,
Prashant

On Thu, Mar 24, 2011 at 9:18 PM, Pinaki Poddar  wrote:

> Hi Prashant,
>  You may like to check out a complete GWT + OpenJPA sample in
> openjpa-examples/opentrader directory.
>
>
>
> -
> Pinaki
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/OpenJPA-Date-Proxy-serialization-problem-when-using-entities-with-GWT-tp6156425p6204055.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>


Re: OpenJPA Date Proxy serialization problem when using entities with GWT

2011-03-24 Thread Pinaki Poddar
Hi Prashant,
  You may like to check out a complete GWT + OpenJPA sample in
openjpa-examples/opentrader directory.

 

-
Pinaki 
--
View this message in context: 
http://openjpa.208410.n2.nabble.com/OpenJPA-Date-Proxy-serialization-problem-when-using-entities-with-GWT-tp6156425p6204055.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: OpenJPA Date Proxy serialization problem when using entities with GWT

2011-03-23 Thread Prashant Bhat
 I don't know much about the benefits of using proxies, but in our
particular usage, all proxies should be removed when the entity is
detached/serialized. Then we can use entities directly in GWT avoiding DTOs
and also with this, client side will not have dependency on OpenJPA at
runtime.

Regards,
Prashant

On Wed, Mar 23, 2011 at 9:22 PM, Michael Dick wrote:

> I haven't had a chance to look at your example application, but I think we
> need to make some changes to the way we handle proxies.
>
> Currently there's no way to prevent proxies from being inserted. It's not
> intuitive when they will be inserted, and they can be tough to remove. What
> I'd propose is to make it work something like this :
>
> if openjpa.ProxyManager.TrackChanges == False :
># No proxies are inserted. Ever.
>
> else :
>
>if openjpa.DetachState.DetachedStateField == "true":
># proxies are inserted when the entity is flushed (or committed)
># proxies are not removed when the entity is detached
># proxies are not removed when the entity is serialized
>
>   elif openjpa.DetachState.DetachedStateField == "transient" :
># proxies are inserted when the entity is flushed (or committed)
># proxies are not removed when the entity is detached
># proxies are removed when the entity is serialized
>
>elif openjpa.DetachState.DetachedStateField == "false" :
># proxies are inserted when the entity is flushed (or committed)
># proxies are removed when the entity is detached
># proxies are removed when the entity is serialized
>
> From what I've seen none of these are accurate for trunk, and the related
> code path is a bit tangled (or I just haven't groked it).
>
> For your specific use case, would you want the proxies to ever be inserted?
>
> -mike
>
>


Re: OpenJPA Date Proxy serialization problem when using entities with GWT

2011-03-23 Thread Michael Dick
I haven't had a chance to look at your example application, but I think we
need to make some changes to the way we handle proxies.

Currently there's no way to prevent proxies from being inserted. It's not
intuitive when they will be inserted, and they can be tough to remove. What
I'd propose is to make it work something like this :

if openjpa.ProxyManager.TrackChanges == False :
# No proxies are inserted. Ever.

else :

if openjpa.DetachState.DetachedStateField == "true":
# proxies are inserted when the entity is flushed (or committed)
# proxies are not removed when the entity is detached
# proxies are not removed when the entity is serialized

   elif openjpa.DetachState.DetachedStateField == "transient" :
# proxies are inserted when the entity is flushed (or committed)
# proxies are not removed when the entity is detached
# proxies are removed when the entity is serialized

elif openjpa.DetachState.DetachedStateField == "false" :
# proxies are inserted when the entity is flushed (or committed)
# proxies are removed when the entity is detached
# proxies are removed when the entity is serialized

>From what I've seen none of these are accurate for trunk, and the related
code path is a bit tangled (or I just haven't groked it).

For your specific use case, would you want the proxies to ever be inserted?

-mike


On Sat, Mar 19, 2011 at 7:27 AM, Prashant Bhat wrote:

> Hi,
>
> I've created a sample project to explore this issue. Please see the
> attached sample project.
>
> To run this test, execute this maven command: mvn compile openjpa:enhance
> gwt:compile test
>
> The GWT compiler takes long time to compile. Once it is complete, this will
> start a jetty server and opens URL http://localhost:8080/ in the default
> browser. Now click on the 'Save Sales Orders' which fails with the following
> exception.
>
> com.google.gwt.user.client.rpc.SerializationException: Type
> 'org.apache.openjpa.util.java$util$Date$proxy'
>
> I really appreciate your help in solving this or any suggestion to use
> alternate approach, Thanks.
>
> Regards,
> Prashant
>
> On Thu, Mar 10, 2011 at 11:26 PM, Michael Dick 
> wrote:
>
>> Hi Prashant,
>>
>> I've been looking into the Date proxies recently. What I've found is that
>> the proxies are removed if you serialize the entity or use detachCopy()
>> (in
>> this case the original entity retains the proxies and the new copy does
>> not
>> have them). I'm looking into a better solution for this use case, but the
>> detachment code is pretty tangled, and it might take a little while to
>> work
>> out a safe option.
>>
>> I'm not sure why using a DTO didn't work for you. How did you copy the
>> date
>> field from your entity?
>>
>> -mike
>>
>> On Wed, Mar 9, 2011 at 9:13 PM, Prashant Bhat 
>> wrote:
>>
>> > Hi All,
>> >
>> > We're developing an application using OpenJpa 2.1, Spring-3.0.5 and
>> > GWT-2.2.0. This integration works for all other types in the entity, but
>> > fails for fields of type Date with the following exception:
>> > --
>> > com.google.gwt.user.client.rpc.SerializationException: Type
>> > 'org.apache.openjpa.util.java$util$Date$proxy' was not included in the
>> set
>> > of types which can be serialized by this SerializationPolicy or its
>> Class
>> > object could not be loaded. For security purposes, this type will not be
>> > serialized.: instance = Sat Dec 31 00:00:00 SGT 2011
>> > --
>> > I tried using DTO instead of using an entity directly, but when date
>> > property is copied from Entity object to DTO, the same proxy will be
>> set.
>> > So
>> > it doesn't work either.
>> >
>> > When searched, I found lot of references to detaching the entity to
>> remove
>> > all proxies needed by Jpa. It works, but this needs to be explicitly
>> > called,
>> > while the same works without calling this, in our Swing app which gets
>> the
>> > serialized objects through Spring Remoting. And also, as there're a lot
>> of
>> > DAOs already written, this is going to be major change.
>> >
>> > So, is there a openjpa configuration setting to use, so that all proxies
>> > are
>> > removed on em.close() ? I really appreciate any help to solve this.
>> >
>> > Thanks,
>> > Prashant
>> >
>>
>
>


Re: OpenJPA Date Proxy serialization problem when using entities with GWT

2011-03-10 Thread Prashant Bhat
Hi Jeremy,

I'm using version="2.0", verified it again now. And I tried the
Compatibility setting you mentioned, but the same exception was thrown.

If it helps in finding cause, I can create a simple GWT application, but it
may take some time for me!

Regards,
Prashant

On Thu, Mar 10, 2011 at 11:42 PM, Jeremy Bauer  wrote:

> Prashant,
>
> According to the OpenJPA migration considerations documentation[1] section
> 1.1.5, clear()/close() will remove proxies automatically upon serialization
> if you have a version 2.0 persistence.xml.  If you are using a version 1.0
> persistence.xml setting this property should result in proxy removal:
>
>   value="IgnoreDetachedStateFieldForProxySerialization=false"/>
>
> hth,
> -Jeremy
>
> [1]
>
> http://openjpa.apache.org/builds/latest/docs/manual/migration_considerations.html
>
> On Wed, Mar 9, 2011 at 9:13 PM, Prashant Bhat 
> wrote:
>
> > Hi All,
> >
> > We're developing an application using OpenJpa 2.1, Spring-3.0.5 and
> > GWT-2.2.0. This integration works for all other types in the entity, but
> > fails for fields of type Date with the following exception:
> > --
> > com.google.gwt.user.client.rpc.SerializationException: Type
> > 'org.apache.openjpa.util.java$util$Date$proxy' was not included in the
> set
> > of types which can be serialized by this SerializationPolicy or its Class
> > object could not be loaded. For security purposes, this type will not be
> > serialized.: instance = Sat Dec 31 00:00:00 SGT 2011
> > --
> > I tried using DTO instead of using an entity directly, but when date
> > property is copied from Entity object to DTO, the same proxy will be set.
> > So
> > it doesn't work either.
> >
> > When searched, I found lot of references to detaching the entity to
> remove
> > all proxies needed by Jpa. It works, but this needs to be explicitly
> > called,
> > while the same works without calling this, in our Swing app which gets
> the
> > serialized objects through Spring Remoting. And also, as there're a lot
> of
> > DAOs already written, this is going to be major change.
> >
> > So, is there a openjpa configuration setting to use, so that all proxies
> > are
> > removed on em.close() ? I really appreciate any help to solve this.
> >
> > Thanks,
> > Prashant
> >
>


Re: OpenJPA Date Proxy serialization problem when using entities with GWT

2011-03-10 Thread Prashant Bhat
Hi Mike,

Thanks for the reply.

Yes, on serialization all the proxies are removed, as it works with our
Swing app which has no dependency on OpenJpa jars. But GWT serialization
seems to work in a different way.

And I've tried detachCopy() and it works. But I'd like to keep existing DAOs
as they're, because entities are loaded from an abstract class which is
common to all services, so then for all queries detachCopy() would be
called. And I tried to call detachCopy()  after loading entities(only in GWT
services), but once the EM is closed, this doesn't work. Btw, I found that
EM.detachAll() throws a NPE, it seems to be a bug.

For copying the properties to DTO, I used a simple approach like this in my
GWT service implementation:
 // Load entities from DAO, using Spring Transactional(readOnly=true)
// starts an EM and is closed on return here
List salesOrderList = salesOrderDao.findSalesOrders(customer);
// convert entity to dto
List salesOrderDtoList = new ArrayList();
for(SalesOrder salesOrder : salesOrderList) {
SalesOrderDto salesOrderDto = new SalesOrderDto();
salesOrderDto.setOrderDate(salesOrder.getOrderDate());
   
   salesOrderDtoList.add(salesOrderDto);
}
return salesOrderDtoList;


Regards,
Prashant


On Thu, Mar 10, 2011 at 11:26 PM, Michael Dick wrote:

> Hi Prashant,
>
> I've been looking into the Date proxies recently. What I've found is that
> the proxies are removed if you serialize the entity or use detachCopy() (in
> this case the original entity retains the proxies and the new copy does not
> have them). I'm looking into a better solution for this use case, but the
> detachment code is pretty tangled, and it might take a little while to work
> out a safe option.
>
> I'm not sure why using a DTO didn't work for you. How did you copy the date
> field from your entity?
>
> -mike
>
> On Wed, Mar 9, 2011 at 9:13 PM, Prashant Bhat 
> wrote:
>
> > Hi All,
> >
> > We're developing an application using OpenJpa 2.1, Spring-3.0.5 and
> > GWT-2.2.0. This integration works for all other types in the entity, but
> > fails for fields of type Date with the following exception:
> > --
> > com.google.gwt.user.client.rpc.SerializationException: Type
> > 'org.apache.openjpa.util.java$util$Date$proxy' was not included in the
> set
> > of types which can be serialized by this SerializationPolicy or its Class
> > object could not be loaded. For security purposes, this type will not be
> > serialized.: instance = Sat Dec 31 00:00:00 SGT 2011
> > --
> > I tried using DTO instead of using an entity directly, but when date
> > property is copied from Entity object to DTO, the same proxy will be set.
> > So
> > it doesn't work either.
> >
> > When searched, I found lot of references to detaching the entity to
> remove
> > all proxies needed by Jpa. It works, but this needs to be explicitly
> > called,
> > while the same works without calling this, in our Swing app which gets
> the
> > serialized objects through Spring Remoting. And also, as there're a lot
> of
> > DAOs already written, this is going to be major change.
> >
> > So, is there a openjpa configuration setting to use, so that all proxies
> > are
> > removed on em.close() ? I really appreciate any help to solve this.
> >
> > Thanks,
> > Prashant
> >
>


Re: OpenJPA Date Proxy serialization problem when using entities with GWT

2011-03-10 Thread Jeremy Bauer
Prashant,

According to the OpenJPA migration considerations documentation[1] section
1.1.5, clear()/close() will remove proxies automatically upon serialization
if you have a version 2.0 persistence.xml.  If you are using a version 1.0
persistence.xml setting this property should result in proxy removal:

  

hth,
-Jeremy

[1]
http://openjpa.apache.org/builds/latest/docs/manual/migration_considerations.html

On Wed, Mar 9, 2011 at 9:13 PM, Prashant Bhat  wrote:

> Hi All,
>
> We're developing an application using OpenJpa 2.1, Spring-3.0.5 and
> GWT-2.2.0. This integration works for all other types in the entity, but
> fails for fields of type Date with the following exception:
> --
> com.google.gwt.user.client.rpc.SerializationException: Type
> 'org.apache.openjpa.util.java$util$Date$proxy' was not included in the set
> of types which can be serialized by this SerializationPolicy or its Class
> object could not be loaded. For security purposes, this type will not be
> serialized.: instance = Sat Dec 31 00:00:00 SGT 2011
> --
> I tried using DTO instead of using an entity directly, but when date
> property is copied from Entity object to DTO, the same proxy will be set.
> So
> it doesn't work either.
>
> When searched, I found lot of references to detaching the entity to remove
> all proxies needed by Jpa. It works, but this needs to be explicitly
> called,
> while the same works without calling this, in our Swing app which gets the
> serialized objects through Spring Remoting. And also, as there're a lot of
> DAOs already written, this is going to be major change.
>
> So, is there a openjpa configuration setting to use, so that all proxies
> are
> removed on em.close() ? I really appreciate any help to solve this.
>
> Thanks,
> Prashant
>


Re: OpenJPA Date Proxy serialization problem when using entities with GWT

2011-03-10 Thread Michael Dick
Hi Prashant,

I've been looking into the Date proxies recently. What I've found is that
the proxies are removed if you serialize the entity or use detachCopy() (in
this case the original entity retains the proxies and the new copy does not
have them). I'm looking into a better solution for this use case, but the
detachment code is pretty tangled, and it might take a little while to work
out a safe option.

I'm not sure why using a DTO didn't work for you. How did you copy the date
field from your entity?

-mike

On Wed, Mar 9, 2011 at 9:13 PM, Prashant Bhat  wrote:

> Hi All,
>
> We're developing an application using OpenJpa 2.1, Spring-3.0.5 and
> GWT-2.2.0. This integration works for all other types in the entity, but
> fails for fields of type Date with the following exception:
> --
> com.google.gwt.user.client.rpc.SerializationException: Type
> 'org.apache.openjpa.util.java$util$Date$proxy' was not included in the set
> of types which can be serialized by this SerializationPolicy or its Class
> object could not be loaded. For security purposes, this type will not be
> serialized.: instance = Sat Dec 31 00:00:00 SGT 2011
> --
> I tried using DTO instead of using an entity directly, but when date
> property is copied from Entity object to DTO, the same proxy will be set.
> So
> it doesn't work either.
>
> When searched, I found lot of references to detaching the entity to remove
> all proxies needed by Jpa. It works, but this needs to be explicitly
> called,
> while the same works without calling this, in our Swing app which gets the
> serialized objects through Spring Remoting. And also, as there're a lot of
> DAOs already written, this is going to be major change.
>
> So, is there a openjpa configuration setting to use, so that all proxies
> are
> removed on em.close() ? I really appreciate any help to solve this.
>
> Thanks,
> Prashant
>


OpenJPA Date Proxy serialization problem when using entities with GWT

2011-03-09 Thread Prashant Bhat
Hi All,

We're developing an application using OpenJpa 2.1, Spring-3.0.5 and
GWT-2.2.0. This integration works for all other types in the entity, but
fails for fields of type Date with the following exception:
--
com.google.gwt.user.client.rpc.SerializationException: Type
'org.apache.openjpa.util.java$util$Date$proxy' was not included in the set
of types which can be serialized by this SerializationPolicy or its Class
object could not be loaded. For security purposes, this type will not be
serialized.: instance = Sat Dec 31 00:00:00 SGT 2011
--
I tried using DTO instead of using an entity directly, but when date
property is copied from Entity object to DTO, the same proxy will be set. So
it doesn't work either.

When searched, I found lot of references to detaching the entity to remove
all proxies needed by Jpa. It works, but this needs to be explicitly called,
while the same works without calling this, in our Swing app which gets the
serialized objects through Spring Remoting. And also, as there're a lot of
DAOs already written, this is going to be major change.

So, is there a openjpa configuration setting to use, so that all proxies are
removed on em.close() ? I really appreciate any help to solve this.

Thanks,
Prashant