Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

'The behavior is undefined if mapping annotations are palces on any instances..." meaning  RSS feed

 
Ranch Hand
Posts: 1676
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In 2.3.2 Explicit Access type


When Access (Property) is applied to an entity class, .... mapping annotation may be placed on the properties of that class....
The behavior is undefined if mapping annotations are placed on any instance variables defined by the class for which Access(Field) is not specified...


What does the behavior is undefined if mapping annotation are place on any instance variables....?


 
Saloon Keeper
Posts: 8740
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It simply means that if you have a class that does not specify @Access(AccessType.FIELD), putting mapping annotations like @Column on a field is nonsensical and may lead to unexpected results.
 
Himai Minh
Ranch Hand
Posts: 1676
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks.
But if I don't specify AccessType.Field, by default, the access type is Field if I put mapping annotation @Id on the field like this:


So, if we have a @Column for name attribute and there is @id for it, we can tell access type is field.
On the other hand, if there is no @Id and no explicit access type and only @Column exist, the behavior is undefined.
Correct me if I am wrong.
 
Creator of Enthuware JWS+ V6
Bartender
Posts: 3094
255
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

On the other hand, if there is no @Id and no explicit access type and only @Column exist, the behavior is undefined. 


Ehhh no. It is wrong if you have an annotation on a field (without the @Access(AccessType.FIELD) ) and the class has an anotation of @Access(AccessType.PROPERTY).

Let me try to explain with an example

To follow the specifications you will have to be explicit about the Address property access:


The specs for this example, but the same applies to Property access:


When Access(FIELD) is applied to an entity class, mapped superclass, or embeddable class, mapping annotations may be placed on the instance variables of that class, and the persistence provider runtime accesses persistent state via the instance variables defined by the class. All non-transient instance variables that are not annotated with the Transient annotation are persistent. When Access(FIELD) is applied to such a class, it is possible to selectively designate individual attributes within the class for property access. To specify a persistent property for access by the persistence provider runtime, that property must be designated Access(PROPERTY). The behavior is undefined if mapping annotations are placed on any properties defined by the class for which Access(PROPERTY) is not specified.



Or in other words:


It is an error if a default access type cannot be determined and an access type is not explicitly specified by means of annotations or the XML descriptor. The behavior of applications that mix the placement of annotations on fields and properties within an entity hierarchy without explicitly specifying the Access annotation is undefined.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!