Return-Path: X-Original-To: apmail-openjpa-dev-archive@www.apache.org Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 227F995ED for ; Tue, 17 Jan 2012 17:18:03 +0000 (UTC) Received: (qmail 91973 invoked by uid 500); 17 Jan 2012 17:18:03 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 91877 invoked by uid 500); 17 Jan 2012 17:18:02 -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 91868 invoked by uid 99); 17 Jan 2012 17:18:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Jan 2012 17:18:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Jan 2012 17:18:00 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id AE2C2151321 for ; Tue, 17 Jan 2012 17:17:40 +0000 (UTC) Date: Tue, 17 Jan 2012 17:17:40 +0000 (UTC) From: "Kevin Sutter (Commented) (JIRA)" To: dev@openjpa.apache.org Message-ID: <276226054.49181.1326820660715.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1561184671.49094.1326819219635.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (OPENJPA-2109) Should @Factory methods fire on Entity Identity fields? MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/OPENJPA-2109?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13187811#comment-13187811 ] Kevin Sutter commented on OPENJPA-2109: --------------------------------------- Please expand on your comment: "Should any kind of transformation on identity fields even be allowed, because of the data integrity/security issues that could arise from it?" Thanks. And, why don't we allow the use of @Externalizer/@Factory with Embedded Id's? Is that just a documented restriction or do we actually have code that prevents this usage? > Should @Factory methods fire on Entity Identity fields? > ------------------------------------------------------- > > Key: OPENJPA-2109 > URL: https://issues.apache.org/jira/browse/OPENJPA-2109 > Project: OpenJPA > Issue Type: Question > Components: kernel > Reporter: Jody Grassel > Priority: Minor > > Question for the OpenJPA community. Recently I had made an observation with the following code: > @Entity > public class JAGExternEntity { > @Id > @Externalizer("JAGExternEntity.toLowercaseString") > @Factory("JAGExternEntity.toUppercaseString") > private String id; > > @Externalizer("JAGExternEntity.toLowercaseString") > @Factory("JAGExternEntity.toUppercaseString") > private String extString; > ... > (Standard default constructor, getter and setter methods) > ... > public String toString() { > return "JAGExternEntity [id=" + id + ", extString=" + extString + "]"; > } > > public static String toLowercaseString(String str) { > return str.toLowerCase(); > } > > public static String toUppercaseString(String str) { > return str.toUpperCase(); > } > } > > > Test Code (JUnit): > > public void test000() throws Exception { > JAGExternEntity jee = new JAGExternEntity(); > jee.setId("SomeIdentity"); > jee.setExtString("Some External String."); > > System.out.println("Pre Persist: " + jee); > > em.getTransaction().begin(); > em.persist(jee); > System.out.println("Post Persist: " + jee); > em.getTransaction().commit(); > System.out.println("Post Commit: " + jee); > > em.clear(); > > em.getTransaction().begin(); > Query q = em.createQuery("SELECT e FROM JAGExternEntity e"); > List resultList = q.getResultList(); > for (JAGExternEntity find : resultList) { > System.out.println("Query Result: " + find); > em.remove(find); > } > em.getTransaction().commit(); > } > > And the test output: > > 517 jag-test INFO [main] openjpa.Runtime - OpenJPA dynamically loaded a validation provider. > 534 jag-test INFO [main] openjpa.Runtime - Starting OpenJPA 2.1.2-SNAPSHOT > 576 jag-test INFO [main] openjpa.jdbc.JDBC - Using dictionary class org.apache.openjpa.jdbc.sql.DerbyDictionary". > Pre Persist: JAGExternEntity [id=SomeIdentity, extString=Some External String.] > Post Persist: JAGExternEntity [id=SomeIdentity, extString=Some External String.] > Post Commit: JAGExternEntity [id=SomeIdentity, extString=Some External String.] > Query Result: JAGExternEntity [id=someidentity, extString=SOME EXTERNAL STRING.] > What the above demonstrates is that @Externalizers will fire for all persistent fields, including identity fields, but @Factories will only fire for non-identity persistent fields. This creates a one-way transformation scenario, where externalized values cannot be reversed back for identity fields. The OpenJPA documentation doesn't contain any text forbidding the use of @Externalizer or @Factory on identity fields (except for embeddable ids, which was the only noted exception.) > I would like to hear the opinions of the community on this behavior. Is it a mistake that @Externalizer is allowed to fire on identity fields, but not @Factory. Or is it a mistake to allow @Externalizer to be allowed to be used by the identity field in the first place? Should any kind of transformation on identity fields even be allowed, because of the data integrity/security issues that could arise from it? -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira