Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A900519188 for ; Mon, 11 Apr 2016 07:02:26 +0000 (UTC) Received: (qmail 79005 invoked by uid 500); 11 Apr 2016 07:02:26 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 78958 invoked by uid 500); 11 Apr 2016 07:02:26 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 78943 invoked by uid 99); 11 Apr 2016 07:02:26 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Apr 2016 07:02:26 +0000 Received: from [192.168.0.7] (unknown [217.133.18.16]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 828A81A0046 for ; Mon, 11 Apr 2016 07:02:25 +0000 (UTC) Subject: Re: UUID generators worth the effort? Reply-To: users@openjpa.apache.org References: <57022A91.6010100@apache.org> To: users@openjpa.apache.org From: =?UTF-8?Q?Francesco_Chicchiricc=c3=b2?= Message-ID: <570B4BFC.4020601@apache.org> Date: Mon, 11 Apr 2016 09:02:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <57022A91.6010100@apache.org> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: quoted-printable Hi all, I went further and built a sample POC [10] which mimics the essentials=20 from Syncope. I have defined an UUIDGenerator implementing Seq (and relying on [3] for = UUID generation), and declared it via @SequenceGenerator(name =3D "uuid", sequenceName =3D=20 "net.tirasa.ilgrosso.uuidpoc.openjpa.UUIDGenerator()") in the @MappedSuperclass of both JPA entities available, plus defined @Id @GeneratedValue(strategy =3D GenerationType.SEQUENCE, generator =3D = "uuid") private UUID id; in both entities. I have also extended the H2Dictionary to support the native UUID type=20 (without such extension, the id column would have had type BLOB). All this above seems to work - at least for the simple JUnit test case=20 provided; I have some questions, though: 1. I have experimented that UUIDGenerator is instantiated twice: would=20 it be possible to defined it as singleton - as it happens for OpenJPA's=20 UUIDType4HexSeq? 2. How would the @SequenceGenerator annotation translates to orm.xml?=20 I've attempted the bare translation but it did not work. 3. The extended logic I have put in my H2Dictionary looks quite poor for = the general case - even though good enough for my specific use case: @Override public String getTypeName(final Column col) { return col.getType() =3D=3D Types.BLOB && (col.isPrimaryKey() ||= =20 col.isForeignKey()) ? "UUID" : super.getTypeName(col); } How much difficult would be to make it proper, e.g. recognize when the=20 class field is java.util.UUID? I'll need such extension for MySQL,=20 MariaDB, PostgreSQL, MS SQL Server and Oracle dictionaries. 4. I am used to rely on openjpa-maven-plugin to generate the=20 database.sql file; how can I configure it to use my H2Dictionary, and=20 not the default? Thanks for your support. Regards. On 04/04/2016 10:49, Francesco Chicchiricc=F2 wrote: > Hi all, > in Syncope we are currently discussing [1] the option to replace our=20 > table generators-based id strategy to something else, based on UUID,=20 > which seem to offer several advantages. > > I have found [2], but I would rather prefer to generated UUID values=20 > manually (via [3] which seems to offer better performance and more=20 > features than the standard JDK's). > > In order to do so, I would replace the current > > @Id > private Long id; > > public Long getKey() { > return id; > } > > in [4], backed by [5], with something like as > > @Id > private UUID id; > > public UUID getKey() { > synchronized(this) { > if (key =3D=3D null) { > key =3D ... // generate via JUG [3] > } > } > return key; > } > > As Syncope supports several DBMSes, I would also like to empower the=20 > underlying capabilities for storing such values: > > * UUID Type for PostgreSQL [6] > * UNIQUEIDENTIFIER for SQL Server [7] > * RAW(16) for Oracle [8] > * BINARY(16) with some optimizations for MySQL / MariaDB [9] or=20 > vanilla with H2 > > Do you have any suggestion about: > > (a) the way how I am planning to support UUID generation > (b) the cleanest way to support DBMS differences (extending the=20 > respective DB dictionaries?) > > TIA > Regards. > > [1] http://markmail.org/message/fhdrwerdwdm3opdx > [2]=20 > http://openjpa.apache.org/builds/2.4.1/apache-openjpa/docs/jpa_overview= _meta_field.html#jpa_overview_meta_gen > [3] https://github.com/cowtowncoder/java-uuid-generator > [4]=20 > https://github.com/apache/syncope/blob/master/core/persistence-jpa/src/= main/java/org/apache/syncope/core/persistence/jpa/entity/user/JPAUser.jav= a > [5]=20 > https://github.com/apache/syncope/blob/master/core/persistence-jpa/src/= main/resources/META-INF/spring-orm.xml#L87-L94 > [6] http://www.postgresql.org/docs/9.3/static/datatype-uuid.html > [7]=20 > http://wiki.ispirer.com/sqlways/sql-server/data-types/uniqueidentifier > [8]=20 > http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions175.htm#= SQLRF51816 > [9] https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/ [10] https://github.com/ilgrosso/OpenJPAUUIDPOC --=20 Francesco Chicchiricc=F2 Tirasa - Open Source Excellence http://www.tirasa.net/ Involved at The Apache Software Foundation: member, Syncope PMC chair, Cocoon PMC, Olingo PMC, CXF committer http://home.apache.org/~ilgrosso/