Re: Null field not persisted for Dates

2016-10-17 Thread Vincenzo D'Aniello
Ok it was what I wanted, an example of the most comprehensive jpa enhancement
applied to OpenJPA.

I missed the part of the plug-in OpenJPA in maven, and so everything is
clear.

Now for reasons of time, I settled with the java reflections, but when I
have some time I'll try with this solution, and I think that will definitely
work.

Thanks for your help!



--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p7589816.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Null field not persisted for Dates

2016-10-16 Thread Mark Struberg
Hi Vincenzo!

No worries, your english is fine. 

The writeExternal is invoked to serialize away the entity. Whether the receiver 
side gets just the normal entity fields (unenhanced so to say) or also the 
_loaded and _dirty fields is a question of the configuration. 

I usually use the following setup:
https://github.com/struberg/lightweightEE/blob/master/backend-api/src/main/resources/META-INF/persistence.xml#L26

Together with the openjpa-maven-plugin to enhance the classes at build time
https://github.com/struberg/lightweightEE/blob/master/backend-api/pom.xml#L66
I should clean up the connection section config. That's a left over from many 
years back. But it should basically work.

I've wrote up a bit about enhancement strategies many years ago, maybe it helps:
https://struberg.wordpress.com/2012/01/08/jpa-enhancement-done-right/


Do you have a small sample which we can use to reproduce the problem?

txs and LieGrue,
strub





> On Saturday, 15 October 2016, 19:25, Vincenzo D'Aniello 
>  wrote:
> > Hi, i've set this property in the persistence unit:
> 
>  value="loaded(DetachedStateField=true)"/> 
> 
> but when the entity object try to be detached, an exception
> NoSuchMethodException is thrown because openjpa try to execute the
> writeExternal method on the entity class object.
> 
> I have not understand abaut enhancer, Enhancement. There is a complete
> example how do remote ejb call with ejb entity beans?
> 
> I use Tomee 1.7.4 naturally with openejb, openjpa, sorry for my english.
> 
> 
> 
> --
> View this message in context: 
> http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p7589809.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> 


Re: Null field not persisted for Dates

2016-10-15 Thread Vincenzo D'Aniello
Hi, i've set this property in the persistence unit:

 

but when the entity object try to be detached, an exception
NoSuchMethodException is thrown because openjpa try to execute the
writeExternal method on the entity class object.

I have not understand abaut enhancer, Enhancement. There is a complete
example how do remote ejb call with ejb entity beans?

I use Tomee 1.7.4 naturally with openejb, openjpa, sorry for my english.



--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p7589809.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Null field not persisted for Dates

2014-05-13 Thread Adil
Hi,

I have tried property name=openjpa.DetachState 
value=fetch-groups/  and it worked fine. but the problem is if i want to
update on field, for that in persistenceObject i populate one field, rest
are null. it will cause problem. Do we have any solution to apply this
behavior on specific field instead of complete JPA entities.

I have tried below code but didn't work for me(persistence.xml
openjpa.DetachState property was not set for below code).

*@Entity
@Table(name=EMPLOYEE)
@FetchGroups({
@FetchGroup(name=employeeDateFetchGroup, attributes={
@FetchAttribute(name=employeeDate)
})
})
class Employee{
.
}
*

and Persistence DAO Layer code:

*Query query = entityManager.createQuery(EMPLOYEE_RETRIEVE_SQL);
query.setParameter(employeeId, identifier);   
OpenJPAQuery kq = OpenJPAPersistence.cast(query);

kq.getFetchPlan().setMaxFetchDepth(3).addFetchGroup(employeeDateFetchGroup);
persistentObject = 
(AppliedFirearmPO)kq.getSingleResult();*



--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p7586404.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Null field not persisted for Dates

2011-05-11 Thread bp_maggie
I tested with this piece of code and it works:

//modified is the instance client had changed
Record modified = (Record) processClientRequest();
EntityManager em = emf.createEntityManager();
Record merged = (Record) em.merge(modified);
//assume begin is a date and client set the date to null, update the date
field after merged
merged.setBegin( modified.getBegin() );

--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p6351057.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Null field not persisted for Dates

2011-02-06 Thread Mark Struberg
please verify if the entities pcStateManager _dirty and _loaded BitSet are set.

If you decompile your entity (using jad or a similar java decompiler) you will 
find a few methods which contains switch/case where you can find which internal 
number the concerned field has.

Both the respective _dirty and _loaded bits should be set.

LieGrue,
strub

--- On Sun, 2/6/11, No1UNo je...@jerrycarter.org wrote:

 From: No1UNo je...@jerrycarter.org
 Subject: Re: Null field not persisted for Dates
 To: users@openjpa.apache.org
 Date: Sunday, February 6, 2011, 4:42 AM
 
 
 On Feb 4, 2011, at 2:13 PM, Jerry Carter wrote:
  Am I right is assuming that null values should be
 copies on merge?  I've reviewed the JPA 2.0
 specification.  I see that 3.2.7.1 does not
 disadvantage null values
  If X is a detached entity, the state of X is
 copied onto a pre-existing managed entity instance X' of the
 same identity or a new managed copy X' of X is created.
  
  but note that 3.2.7.2 leaves some wiggle room for
 implementations supporting lazy loading.  I'm happy to
 file the report if this is a bug.
  
  I see that FetchType.EAGER is already specified (by
 default), so lazy loading is already turned off for the
 field in question.  Do I understand that (post-merge),
 setting the value to null should cause the value to be
 persisted?
 
 I completed an experiment which rules this option
 out.  Looking at the value after the merge and after a
 flush, I can see that the null value is present in Java but
 that the database is not updated.
 
 Time to review the documentation for your other
 suggestion:
 
  On Feb 4, 2011, at 1:56 PM, Rick Curtis [via OpenJPA]
 wrote:
  That would be the problem then. We lost track of
 the fact that you set this 
  field to null, and assume that it wasn't
 loaded.  Please review the 
  openjpa.DetachState [1] docs for more info. You
 could set the property 
  listed below so that we will stream our
 DetachedStateManager around. 
  
  property name=openjpa.DetachState 
  value=fetch-groups(DetachedStateField=true)/
 
  
  [1] 
  http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_detach_graph
 
 
 -- 
 View this message in context: 
 http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p5997071.html
 Sent from the OpenJPA Users mailing list archive at
 Nabble.com.
 





Re: Null field not persisted for Dates

2011-02-05 Thread No1UNo


On Feb 4, 2011, at 2:13 PM, Jerry Carter wrote:
 Am I right is assuming that null values should be copies on merge?  I've 
 reviewed the JPA 2.0 specification.  I see that 3.2.7.1 does not disadvantage 
 null values
 If X is a detached entity, the state of X is copied onto a pre-existing 
 managed entity instance X' of the same identity or a new managed copy X' of 
 X is created.
 
 but note that 3.2.7.2 leaves some wiggle room for implementations supporting 
 lazy loading.  I'm happy to file the report if this is a bug.
 
 I see that FetchType.EAGER is already specified (by default), so lazy loading 
 is already turned off for the field in question.  Do I understand that 
 (post-merge), setting the value to null should cause the value to be 
 persisted?

I completed an experiment which rules this option out.  Looking at the value 
after the merge and after a flush, I can see that the null value is present in 
Java but that the database is not updated.

Time to review the documentation for your other suggestion:

 On Feb 4, 2011, at 1:56 PM, Rick Curtis [via OpenJPA] wrote:
 That would be the problem then. We lost track of the fact that you set this 
 field to null, and assume that it wasn't loaded.  Please review the 
 openjpa.DetachState [1] docs for more info. You could set the property 
 listed below so that we will stream our DetachedStateManager around. 
 
 property name=openjpa.DetachState 
 value=fetch-groups(DetachedStateField=true)/ 
 
 [1] 
 http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_detach_graph


-- 
View this message in context: 
http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p5997071.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Null field not persisted for Dates

2011-02-04 Thread Rick Curtis
Jerry -

Is the Entity which you are trying to update being serialized/deserialized?

Thanks,
Rick

On Fri, Feb 4, 2011 at 12:25 PM, Jerry Carter je...@jerrycarter.org wrote:

 Using OpenJPA 2.0.1, I have a date field in my entity.  Setting the field
 to a non-null value causes the data to be persisted as one would expect.
  Setting the value to null, however, does not trigger an UPDATE operation.
  I'm still digging, but I'm sure that someone else has encountered this.

 FWIW, the annotations for the field are simple:

 @Temporal(TemporalType.DATE)
 @Column(name=purchase_date private Date purchaseDate;

 I do not specify 'nullable', but it defaults to true and the field supports
 a NULL value in the database.

 -=- Jerry






Re: Null field not persisted for Dates

2011-02-04 Thread No1UNo

Yes, it is.  The object is changed remotely and then merged.  The data on the 
wire is fine.

On Feb 4, 2011, at 1:47 PM, Rick Curtis [via OpenJPA] wrote:

 Jerry - 
 
 Is the Entity which you are trying to update being serialized/deserialized? 
 
 Thanks, 
 Rick 
 
 On Fri, Feb 4, 2011 at 12:25 PM, Jerry Carter [hidden email] wrote: 
 
  Using OpenJPA 2.0.1, I have a date field in my entity.  Setting the field 
  to a non-null value causes the data to be persisted as one would expect. 
   Setting the value to null, however, does not trigger an UPDATE operation. 
   I'm still digging, but I'm sure that someone else has encountered this. 
  
  FWIW, the annotations for the field are simple: 
  
  @Temporal(TemporalType.DATE) 
  @Column(name=purchase_date private Date purchaseDate; 
  
  I do not specify 'nullable', but it defaults to true and the field supports 
  a NULL value in the database. 
  
  -=- Jerry 
  
  
  
  
 
 
 If you reply to this email, your message will be added to the discussion 
 below:
 http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p5993586.html
 To start a new topic under OpenJPA Users, email 
 ml-node+208411-1703014788-244...@n2.nabble.com 
 To unsubscribe from OpenJPA Users, click here.


-- 
View this message in context: 
http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p5993590.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Null field not persisted for Dates

2011-02-04 Thread Rick Curtis
Jerry -

That would be the problem then. We lost track of the fact that you set this
field to null, and assume that it wasn't loaded.  Please review the
openjpa.DetachState [1] docs for more info. You could set the property
listed below so that we will stream our DetachedStateManager around.

property name=openjpa.DetachState
value=fetch-groups(DetachedStateField=true)/

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

Thanks,
Rick

On Fri, Feb 4, 2011 at 12:49 PM, No1UNo je...@jerrycarter.org wrote:


 Yes, it is.  The object is changed remotely and then merged.  The data on
 the wire is fine.

 On Feb 4, 2011, at 1:47 PM, Rick Curtis [via OpenJPA] wrote:

  Jerry -
 
  Is the Entity which you are trying to update being
 serialized/deserialized?
 
  Thanks,
  Rick
 
  On Fri, Feb 4, 2011 at 12:25 PM, Jerry Carter [hidden email] wrote:
 
   Using OpenJPA 2.0.1, I have a date field in my entity.  Setting the
 field
   to a non-null value causes the data to be persisted as one would
 expect.
Setting the value to null, however, does not trigger an UPDATE
 operation.
I'm still digging, but I'm sure that someone else has encountered
 this.
  
   FWIW, the annotations for the field are simple:
  
   @Temporal(TemporalType.DATE)
   @Column(name=purchase_date private Date purchaseDate;
  
   I do not specify 'nullable', but it defaults to true and the field
 supports
   a NULL value in the database.
  
   -=- Jerry



Re: Null field not persisted for Dates

2011-02-04 Thread No1UNo

Rick:

First of all, thank you very much for the quick response and definitive answer.

Am I right is assuming that null values should be copies on merge?  I've 
reviewed the JPA 2.0 specification.  I see that 3.2.7.1 does not disadvantage 
null values
 If X is a detached entity, the state of X is copied onto a pre-existing 
 managed entity instance X' of the same identity or a new managed copy X' of X 
 is created.

but note that 3.2.7.2 leaves some wiggle room for implementations supporting 
lazy loading.  I'm happy to file the report if this is a bug.

I see that FetchType.EAGER is already specified (by default), so lazy loading 
is already turned off for the field in question.  Do I understand that 
(post-merge), setting the value to null should cause the value to be persisted?

Thanks.

-=- Jerry


On Feb 4, 2011, at 1:56 PM, Rick Curtis [via OpenJPA] wrote:

 Jerry - 
 
 That would be the problem then. We lost track of the fact that you set this 
 field to null, and assume that it wasn't loaded.  Please review the 
 openjpa.DetachState [1] docs for more info. You could set the property 
 listed below so that we will stream our DetachedStateManager around. 
 
 property name=openjpa.DetachState 
 value=fetch-groups(DetachedStateField=true)/ 
 
 [1] 
 http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_detach_graph
 
 Thanks, 
 Rick 
 
 On Fri, Feb 4, 2011 at 12:49 PM, No1UNo [hidden email] wrote: 
 
  
  Yes, it is.  The object is changed remotely and then merged.  The data on 
  the wire is fine. 
  
  On Feb 4, 2011, at 1:47 PM, Rick Curtis [via OpenJPA] wrote: 
  
   Jerry - 
   
   Is the Entity which you are trying to update being 
  serialized/deserialized? 
   
   Thanks, 
   Rick 
   
   On Fri, Feb 4, 2011 at 12:25 PM, Jerry Carter [hidden email] wrote: 
   
Using OpenJPA 2.0.1, I have a date field in my entity.  Setting the 
  field 
to a non-null value causes the data to be persisted as one would 
  expect. 
 Setting the value to null, however, does not trigger an UPDATE 
  operation. 
 I'm still digging, but I'm sure that someone else has encountered 
  this. 

FWIW, the annotations for the field are simple: 

@Temporal(TemporalType.DATE) 
@Column(name=purchase_date private Date purchaseDate; 

I do not specify 'nullable', but it defaults to true and the field 
  supports 
a NULL value in the database. 

-=- Jerry 
  
 
 
 If you reply to this email, your message will be added to the discussion 
 below:
 http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p5993617.html
 To start a new topic under OpenJPA Users, email 
 ml-node+208411-1703014788-244...@n2.nabble.com 
 To unsubscribe from OpenJPA Users, click here.


-- 
View this message in context: 
http://openjpa.208410.n2.nabble.com/Null-field-not-persisted-for-Dates-tp5993519p5993681.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Null field not persisted for Dates

2011-02-04 Thread Mark Struberg
Jerry,

I had the same problem, and now use
 
property name=openjpa.DetachState
 value=loaded(DetachedStateField=true)/

I use DetachStrategy 'loaded' instead of 'fetch-groups' because fetch-groups 
gave me lots of problems.

Please be aware that the entities should be Serializable and there are 
currently some problems with Externalizing if you use @Inheritance. See 
OPENJPA-1912 for more info [1].

LieGrue,
strub


[1] https://issues.apache.org/jira/browse/OPENJPA-1912


--- On Fri, 2/4/11, Rick Curtis curti...@gmail.com wrote:

 From: Rick Curtis curti...@gmail.com
 Subject: Re: Null field not persisted for Dates
 To: users@openjpa.apache.org
 Date: Friday, February 4, 2011, 6:55 PM
 Jerry -
 
 That would be the problem then. We lost track of the fact
 that you set this
 field to null, and assume that it wasn't loaded. 
 Please review the
 openjpa.DetachState [1] docs for more info. You could set
 the property
 listed below so that we will stream our
 DetachedStateManager around.
 
 property name=openjpa.DetachState
 value=fetch-groups(DetachedStateField=true)/
 
 [1]
 http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_detach_graph
 
 Thanks,
 Rick
 
 On Fri, Feb 4, 2011 at 12:49 PM, No1UNo je...@jerrycarter.org
 wrote:
 
 
  Yes, it is.  The object is changed remotely and
 then merged.  The data on
  the wire is fine.
 
  On Feb 4, 2011, at 1:47 PM, Rick Curtis [via OpenJPA]
 wrote:
 
   Jerry -
  
   Is the Entity which you are trying to update
 being
  serialized/deserialized?
  
   Thanks,
   Rick
  
   On Fri, Feb 4, 2011 at 12:25 PM, Jerry Carter
 [hidden email] wrote:
  
Using OpenJPA 2.0.1, I have a date field in
 my entity.  Setting the
  field
to a non-null value causes the data to be
 persisted as one would
  expect.
     Setting the value to null, however,
 does not trigger an UPDATE
  operation.
     I'm still digging, but I'm sure that
 someone else has encountered
  this.
   
FWIW, the annotations for the field are
 simple:
   
@Temporal(TemporalType.DATE)
@Column(name=purchase_date private Date
 purchaseDate;
   
I do not specify 'nullable', but it defaults
 to true and the field
  supports
a NULL value in the database.
   
-=- Jerry