-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: static final fields? (when using annotations)
PostPosted: Tue Feb 15, 2005 5:51 pm 
Newbie

Joined: Fri Sep 17, 2004 4:06 pm
Posts: 10
Location: Poland
Hello,

I'm using hibernate (3.0 beta 3) with annotations (3.0 alpha 2).

I'm testing new annotations features on entities with field access type.
This is a simple domain model. Two entites connected with many-to-many
association. Those entities also contain static final fields (for example:
serialVersionUID from Serializable).

Hibernate-annotation adds those static final fields to the list
of persistent fields. It tries to store them in database. Is this
normal behaviour? What about situation when value of those field
will be changed with an external tool (sql console)? Application
will crash during setting those fields.

Normally this isn't a problem. To fix it, you must add @Transient
annotation to the static final fields.

But when using aspectj weaver who adds some static final fields
to the bytecode (static part of a join points), I'm not able to
add any annotation to byte code :/

best regads, Michal


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 19, 2005 8:02 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum,
AspectJ will clash with most of the EJB3 implementations, I imagine.
Use PROPERTY access or plain XML descriptor.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 8:12 am 
Newbie

Joined: Fri Sep 17, 2004 4:06 pm
Posts: 10
Location: Poland
emmanuel wrote:
AspectJ will clash with most of the EJB3 implementations, I imagine.
Use PROPERTY access or plain XML descriptor.


I'm writing persistence aspect, which uses hibernate system
for persisting entities. The annotation hibernate's subproject
is very handy for my purposes. I would like to used.

I patched your AnnotationBinder class and now final fields
aren't added into cfg.

I think previous behaviour was false. I can't imagine persisting
final fields ... do you?

Will it be changed in the future? I could provide a patch...

best regards, Michal


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 12:56 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Interesting, please forward your opinion to ejb3-feebacks@sun.com

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 8:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
does the ejb3 spec really states that *static fields* is meant to be persisted ?

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 10:10 am 
Newbie

Joined: Fri Sep 17, 2004 4:06 pm
Posts: 10
Location: Poland
The '2.1.1 Persistent Fields and Properties' section of EJB3 specification
(Persistence API) says:

Quote:
If the entity is annotated with the annotation member value
access=FIELD, the container accesses instance variables directly and all
non-transient instance variables that are not annotated with the
Transient annotation are persistent.


As you can see, there is nothing about final or static fields.

I post my opinion/comment to ejb-feedback as emmanuel suggested.

best regards, Michal


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 1:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
thanks, I'll let you know.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 8:22 pm 
Newbie

Joined: Fri Sep 17, 2004 4:06 pm
Posts: 10
Location: Poland
I've got an answer from ejb3-feedback. I'll pasted it:

Code:
Date: Tue, 1 Mar 2005 08:35:53 +1300
From: "Evan Ireland" <eireland@sybase.com>
Subject: RE: ejb3-edr2 persistence suggestion (final fields)


"static" fields should not be persisted, as they are not "instance" fields.
@Transient shouldn't be required for "static" fields.

> -----Original Message-----
> From: misto@sysop.ci.pwr.wroc.pl
> [mailto:misto@sysop.ci.pwr.wroc.pl]On Behalf Of Michal Stochmialek
> Sent: Monday, 28 February 2005 10:28 p.m.
> To: ejb3-edr2-feedback@sun.com
> Subject: ejb3-edr2 persistence suggestion (final fields)
>
>
> Hello,
>
> I'm testing an alpha implementation of hibernate annotations,
> which implements
> ejb3-edr2 for specification of o/r mapping.  While those tests, I run into
> a problem, which is a result of contents of Persistence API from
> the second
> draft of ejb3 spec.
>
> The '2.1.1 Persistent Fields and Properties' section says:
>
>    If the entity is annotated with the annotation member value
>    access=FIELD, the container accesses instance variables
> directly and all
>    non-transient instance variables that are not annotated with the
>    Transient annotation are persistent.
>
>
> But what a about final fields?  Should they be persisted too?  Container's
> implementation will surely throw an exception, while trying to
> set final field.
> So if this can't be implemented, then why not exclude final fields as it
> was done for transient fields...
>
> On the other hand, I can't think any case when persisting final field could
> be handy?
>
>
> I run into this problem when I've added serialVersionUID field from the
> Serializable interface. Of course, the solution was ease.  I simply added
> @Transient annotation.
>
> But the problem returned when I was using aspectJ weaver, which
> adds a static
> part of join point as a static final field to a target classes.
> In this case,
> I'm not able to add @Transient annotation. And I don't know any
> other solution...
>
>
> Could You make some comment in this area? Do you think final fields should
> be persisted? Can I expect any changes in specification under this topic?
>
> best regards,
> --
> Michal Stochmialek <misto@e-informatyka.pl>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 9:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No, this is not an aswer. This is still an ongoing discussion. It will be surely disambiguous in the next draft.
Thanks for your feedback.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 5:10 am 
Newbie

Joined: Fri Sep 17, 2004 4:06 pm
Posts: 10
Location: Poland
emmanuel wrote:
No, this is not an aswer. This is still an ongoing discussion. It will be surely disambiguous in the next draft.
Thanks for your feedback.


Well... that is a clear aswer for me :) And I suspect, that
contents of that paragraph in specification won't be changed.
Static fields aren't instance fields for sure ;)

But since hibernate team is within expert group, I wll not
continue this thread...

I looking forward for new version of hibernate-annotation.

best regards, Michal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.