Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 696 invoked from network); 27 Jul 2009 19:35:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Jul 2009 19:35:59 -0000 Received: (qmail 81268 invoked by uid 500); 27 Jul 2009 19:37:04 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 81234 invoked by uid 500); 27 Jul 2009 19:37:04 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 81224 invoked by uid 99); 27 Jul 2009 19:37:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jul 2009 19:37:04 +0000 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [192.18.43.132] (HELO sca-es-mail-1.sun.com) (192.18.43.132) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jul 2009 19:36:54 +0000 Received: from fe-sfbay-10.sun.com ([192.18.43.129]) by sca-es-mail-1.sun.com (8.13.7+Sun/8.12.9) with ESMTP id n6RJaMFx015523 for ; Mon, 27 Jul 2009 12:36:34 -0700 (PDT) MIME-version: 1.0 Received: from conversion-daemon.fe-sfbay-10.sun.com by fe-sfbay-10.sun.com (Sun Java(tm) System Messaging Server 7u2-7.02 64bit (built Apr 16 2009)) id <0KNG00200GYBZI00@fe-sfbay-10.sun.com> for dev@openjpa.apache.org; Mon, 27 Jul 2009 12:36:22 -0700 (PDT) Received: from dhcp-usca03-225-69.SFBay.Sun.COM ([unknown] [129.145.225.69]) by fe-sfbay-10.sun.com (Sun Java(tm) System Messaging Server 7u2-7.02 64bit (built Apr 16 2009)) with ESMTPSA id <0KNG00HBOH4LQZ90@fe-sfbay-10.sun.com> for dev@openjpa.apache.org; Mon, 27 Jul 2009 12:36:21 -0700 (PDT) Date: Mon, 27 Jul 2009 12:36:20 -0700 From: Craig L Russell Subject: Re: Curious about subclassing rather than entity enhancement In-reply-to: <2EFDE7AD867BF346BA5130160871B9920CBE3A47@RHV-EXM-03.corp.ebay.com> Sender: Craig.Russell@Sun.COM To: dev@openjpa.apache.org Message-id: <89104425-00FA-4321-8900-B8A87C86CF8A@SUN.com> X-Mailer: Apple Mail (2.935.3) Content-type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1; boundary=Apple-Mail-26--166758054 References: <2EFDE7AD867BF346BA5130160871B9920CBE3806@RHV-EXM-03.corp.ebay.com> <0DD60B4C-91C2-40C6-954E-D6263735465C@SUN.com> <2EFDE7AD867BF346BA5130160871B9920CBE3A47@RHV-EXM-03.corp.ebay.com> X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-26--166758054 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Hi Mike, On Jul 27, 2009, at 12:07 PM, Yawn, Mike wrote: > Hi Craig, > > Thanks for the details ... see below > >> -----Original Message----- >> From: Craig.Russell@Sun.COM [mailto:Craig.Russell@Sun.COM] >> Sent: Monday, July 27, 2009 10:06 AM >> To: dev@openjpa.apache.org >> Subject: Re: Curious about subclassing rather than entity enhancement >> >> Hi Mike, >> >> On Jul 27, 2009, at 8:45 AM, Yawn, Mike wrote: >> >>> >>> >>> I'm curious about something I read on the 'Entity Enhancement' page. >>> Currently, our "JPA-like" implementation of annotations uses the >>> standard JPA annotations, but on an interface rather than a class. >> >> This is a very common (good) pattern for persistence. > > [Yawn, Mike] But one that seems to be expressly prohibited by JPA spec > (Section 2.1, "The entity class must be a top-level class. An enum or > interface must not be designated as an entity.". Does OpenJPA allow > this? Yes. See 5.3 of the OpenJPA manual "Managed Interfaces". > (If not currently, and we made modifications to work with > interfaces, would OpenJPA be interested in this code or should we plan > to keep it in our own branch?) > >> >>> Then, our code generation generates the implementation classes from >>> the >>> interface; we don't ever add or modify code behind the user's back, > so >>> all the implementation code is fully visible. >> >> So you need a factory to allow the user to create a new instance of >> the implementation class. How do you tell the user what to "new", or >> perhaps you have a factory with a method like T >> newInstance(Class interface)? > > [Yawn, Mike] We have a DAO class that provides basic lifecycle > functionality (insert, update, delete, findByPK, plus user-added > queries). The DAO also provides a createLocal() method that returns a > non-persistent (local) data object that can later be passed to the > 'insert' method. The return type of createLocal is the entity > interface, and what we return is the implementation class with all of > the state tracking, etc. So our EntityManager methods would mostly be > calling the DAO. > >>> On the entity enhancement page, there is a statement that "Some JPA >>> providers auto-generate new subclasses or proxy objects that front >>> the >>> user's Entity objects at runtime" ...., and I'm curious how this >>> works >>> given that it seems that the mechanism for creating an entity object >>> is to call "new" on it. >> >> This is how users create an entity to persist. But once it's >> persisted, the provider has its own factory that it uses when >> fetching >> instances from the database. > > [Yawn, Mike] persist doesn't return an object to the caller -- once an > object is initially persisted, can the user continue to work with that > object (modify fields), or do they need to retrieve the object from > the > EntityManager first? Because in the first case I don't see how the > implementation can be detecting any state changes to the object. There are some corner cases if you persist an entity, flush it to the database, and then continue to modify it. But if you persist and commit, these issues go away. After commit, the instance is detached and you need to reacquire the persistent instance from the entity manager. Craig > >>> So, if there is a JPA-annotated class that >>> represents the entity, and then a JPA implementer creates a subclass >>> of >>> this to provide loaded / dirty tracking, etc., it seems that any >>> instantiation of the Entity via "new" would be getting the >>> annotated >>> base class, not the subclass with the implementation of these >>> features. >> >> Right. >> >>> How is that being handled in JPA implementations that use subclasses >>> rather than byte-code weaving ? >> >> Byte-code enhancement is done primarily to allow detection of >> changes, >> which by definition isn't needed for new instances (all fields are >> considered changed for newly persisted instances). >> >> Craig >>> >>> >>> >>> >>> >>> Thanks, >>> >>> Mike Yawn >>> >>> eBay Inc. >>> >> >> Craig L Russell >> Architect, Sun Java Enterprise System http://db.apache.org/jdo >> 408 276-5638 mailto:Craig.Russell@sun.com >> P.S. A good JDO? O, Gasp! > > [Yawn, Mike] Hmm, that P.S. looks anagram-y but I can't decipher it. > > Mike Craig L Russell Architect, Sun Java Enterprise System http://db.apache.org/jdo 408 276-5638 mailto:Craig.Russell@sun.com P.S. A good JDO? O, Gasp! --Apple-Mail-26--166758054 Content-Disposition: attachment; filename=smime.p7s Content-Type: application/pkcs7-signature; name=smime.p7s Content-Transfer-Encoding: base64 MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIGUDCCAwkw ggJyoAMCAQICEDXZ+Ig/3d9DjJZ8u++ZnC0wDQYJKoZIhvcNAQEFBQAwYjELMAkGA1UEBhMCWkEx JTAjBgNVBAoTHFRoYXd0ZSBDb25zdWx0aW5nIChQdHkpIEx0ZC4xLDAqBgNVBAMTI1RoYXd0ZSBQ ZXJzb25hbCBGcmVlbWFpbCBJc3N1aW5nIENBMB4XDTA4MTIwOTE4MTYwMloXDTA5MTIwOTE4MTYw MlowbDEQMA4GA1UEBBMHUnVzc2VsbDEUMBIGA1UEKhMLQ3JhaWcgTGFpcmQxHDAaBgNVBAMTE0Ny YWlnIExhaXJkIFJ1c3NlbGwxJDAiBgkqhkiG9w0BCQEWFUNyYWlnLlJ1c3NlbGxAU3VuLkNPTTCC ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOe3oksetTgSiqqWllhIYBT0dWhR4CitzXDf +ETyrtEF2HWRRpfwixLpV1Az8wwFzNKfjvQn3tQh0A/VDDeepDEM9TKLP+D6qShLR/KTf5kCMyT4 mILJYIDo/JMmTIH5jceojvlTDFd0gd+XXNAGGz1Wu2XxfvFDE/lpFnQkKYE+VjjENONy4JlkJnOI rSfMlb+zHPAUmMTtmhxYIDLgov4Jv2Z5pUKZMpNcYr+7jJeUxkxKwWm4im56h7CGP0Yhkq2Je506 mqKCFImxofBjkHZISVS5m7WaGs4lViDtwLQEPty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