Hi,Note that with OpenJPA, if you were to explicitly enhance the other classes that access the visible persistent fields directly, things would work.
-Patrick On Jun 17, 2008, at 3:50 PM, Andrei Tchijov wrote:
Thanks Mike. It makes perfect sense. I assume this is due to the fact that "@Entity" class gets "enhanced", not all other classes which happen to use it.On Jun 17, 2008, at 17:16 , Michael Dick wrote:Hi Andrei,You're not alone, I had the same misconception. Field and property access apply to how the persistence provider runtime accesses the state of an entity. Regardless of the access type the client should use the entity'saccessor methods. From section 2.1 and 2.1.1 of the JPA specification 2.1 . . .The persistent state of an entity is represented by instance variables,which may correspond to Java-Beans properties. An instance variable may be directly accessed only fromwithin the methods of the entity by the entity instance itself.* Instance variables must not be accessed by clients of the entity. The state of the entity is available to clients only through the entity's accessor methods (getter/setter methods)or other business methods*. Instance variables must be private, protected,or package visibility. 2.1.1 Persistent Fields and PropertiesThe persistent state of an entity is accessed by the persistence providerruntime[1] either via JavaBeansstyle property accessors or via instance variables. A single access type(field or property access) appliesto an entity hierarchy. When annotations are used, the placement of themapping annotations on eitherthe persistent fields or persistent properties of the entity class specifiesthe access type as being either field- or property-based access respectively. . . . [1] The term "persistence provider runtime" refers to the runtimeenvironment of the persistence implementation. In Java EE environments, this may be the Java EE container or a third-party persistence providerimplementation integrated with it. . . .So technically the second option is the more correct way to set a statevariable. Hope this helps, -mikeOn Tue, Jun 17, 2008 at 2:27 PM, Andrei Tchijov <[EMAIL PROTECTED] >wrote:I guess I m doing something wrong. Please enlighten me what it is I amdoing wrong. I have a class with number of fields. One of which is boolean. @Entity class A { ... @Basic boolean foo; ... }OpenJPA doing wonderful job of retrieving "state" of the objects of this class (including 'foo' field). What puzzles me is that it seems to fail todo "opposite". Somewhere else in my code I have ... _tx.begin(); A a = getA(); a.foo = !a.foo; _tx.commit(); ...It looks similar enough to examples from documentation, but it does not work. I am quite confident that "a" is in "attached" state when I am trying to change "condition" field (_em.contans(a ) returns true ). What makes mereally puzzled is that if I change code like this: @Entity class A { ... @Basic boolean foo; ... public void setFoo( boolean v ) { this.foo = v; } } ... _tx.begin(); A a = getA(); a.setFoo( ! a.foo ); _tx.commit(); ... To complete picture, I should mention that I am running "outside of container" (stand alone application). Any help will be highly appreciated. Andrei
-- Patrick Linskey 202 669 5907
smime.p7s
Description: S/MIME cryptographic signature
