Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 54282 invoked from network); 18 Dec 2007 21:38:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Dec 2007 21:38:26 -0000 Received: (qmail 2897 invoked by uid 500); 18 Dec 2007 21:38:15 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 2872 invoked by uid 500); 18 Dec 2007 21:38:15 -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 2863 invoked by uid 99); 18 Dec 2007 21:38:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Dec 2007 13:38:15 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of michael.d.dick@gmail.com designates 72.14.202.176 as permitted sender) Received: from [72.14.202.176] (HELO ro-out-1112.google.com) (72.14.202.176) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Dec 2007 21:37:54 +0000 Received: by ro-out-1112.google.com with SMTP id p4so3579515roc.5 for ; Tue, 18 Dec 2007 13:37:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=/kVDyJ8N01W/iDW5qLBfJ3eIJFSKTuRTHE1S1NaCOsM=; b=BAyEaW0HI5pLeM0QPZSeSUS4T9EAcN5yxXx0O700ynkZur5akl03BXd7LxwbiRQiMoPjwLMEXi09JMEt+XgAKlXjKiaqYglKkm4H9eXgk+w49Ya9ZIC7z8Zk7fRaMLQFxlmNuFchzDkuz6NbNTwjpOy89qhLqpXJZOwj9lq/lWs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=YB7fifgv+W2RTr6zMd5SfekxEaySaG6fICBOVs23TTpg87MY1H3s5+GgDXDmcowLKW6BzteiNGu/3b3y3lswhhLsPXyWyAn63Bdo/ShHXpyjglQDMl8xtnyOiK4p5o82Cx+yjWPtb82a/EyZ/nuTtMfkRiZeXx85vjPsbi0fOJI= Received: by 10.114.146.1 with SMTP id t1mr836002wad.20.1198013876325; Tue, 18 Dec 2007 13:37:56 -0800 (PST) Received: by 10.114.200.3 with HTTP; Tue, 18 Dec 2007 13:37:56 -0800 (PST) Message-ID: <72c1350f0712181337j5bf409c9i7d43b1c5b821bc77@mail.gmail.com> Date: Tue, 18 Dec 2007 15:37:56 -0600 From: "Michael Dick" To: dev@openjpa.apache.org Subject: Re: URGENT: Re: Generic (user) GeneratedValue In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_15567_25535016.1198013876312" References: <7262f25e0711051247x5b7cc50dwdbcaf9d5acdd9969@mail.gmail.com> <7262f25e0711051309w6558713l3b5c610d8cbe3acc@mail.gmail.com> <7262f25e0711051332x5e5963a1i49e6043e09c7a59f@mail.gmail.com> <47679E09.3040602@space-comm.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_15567_25535016.1198013876312 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Please do so. We'll be happy to look at the patch. -Mike On Dec 18, 2007 12:57 PM, Miroslav Nachev wrote: > What do you think if I register an enhancement and then attach a patch if > the new feature which will fix this problem? > In short I will add new enumeration in ValueStrategies. The new > enumeration > will be named CUSTOM or GENERIC or another name. Then I will do the > relevant > changes in the code. Then in the switch statement will be one more case as > follow: > switch (strategy) > { > case ValueStrategies.SEQUENCE: > case ValueStrategies.UUID_STRING: > case ValueStrategies.UUID_HEX: > case ValueStrategies.CUSTOM: > default: > } > > > Miro. > > > > On 12/18/07, Miroslav Nachev wrote: > > > > Hi, > > > > From this mail I understand that the only way in OpenJPA to create > Custom > > Identifier is using "Sequence" like that: > > @Id > > @Column(name = "Data_Object_Id", nullable = false) > > @SequenceGenerator(name="DataObjectsSeq", sequenceName=" > > test.DataObjectsGenerator") > > @GeneratedValue(strategy=GenerationType.SEQUENCE, > > generator="DataObjectsSeq") > > private BigDecimal dataObjectId; > > > > In my test case I am using MySQL which doesn't support Sequences in > > principal and maybe this is a problem. It seams that if the database > doesn't > > support Sequences it is not possible to create Generic Generated Value. > But > > this is not the expected behavior because it is possible to create > > UUID_STRING and UUID_HEX which are not part of any databases. When I > look at > > the code I see the following code in class ImplHelper.java: > > private static Object generateValue(StoreContext ctx, ClassMetaData > > meta, FieldMetaData fmd, int typeCode)\ > > { > > ... > > switch (strategy) > > { > > case ValueStrategies.SEQUENCE: > > ... > > return JavaTypes.convert(seq.next(ctx, meta), typeCode); > > break; > > case ValueStrategies.UUID_STRING: > > return UUIDGenerator.nextString(); > > case ValueStrategies.UUID_HEX: > > return UUIDGenerator.nextHex(); > > default: > > return null; > > } > > } > > > > When I try to create Generic Generated Value using Sequence in database > > which doesn't support Sequences I have exception. > > Somebody tell me that I have to use last_insert_id as follow: > > dbDict.nextSequenceQuery = "SELECT LAST_INSERT_ID()" > > I do that but then nobody invoke my class test.DataObjectsGenerator os > > some of it methods. > > > > From the above code and my tests it seems that theoretically is not > > possible to have custom (generic) Generated Value using database which > > doesn't support sequences. > > Is that a bug? Do you have any idea how to solve it? > > > > Finally I can replace the database with PostgreSQL but the problem will > > not be solved and will still exists. > > > > > > Regards, > > Miro. > > > > > > > > Patrick Linskey wrote: > > > > If you want it to be globally available, you can make it the default > > implementation for use by @GenerationType.SEQUENCE by specifying it in > > the openjpa.Sequence property. > > > > If you want to use it in just some circumstances, or want to use > > different configurations / instances for different types, then you can > > set up named sequences as per the examples in the section I pointed > > you to earlier, and then list the class name in the value. The example > > would look like so: > > > > @SequenceGenerator(name="MyCustomSeq", sequence=" > fully.qualified.ClassName") > > > > Or, if you wanted to set some configuration options on the instance: > > > > @SequenceGenerator(name="MyCustomSeq", > > sequence="fully.qualified.ClassName(InitialValue=5,BitLength=32") > > > > This would work provided that your class had methods called > > setInitialValue() and setBitLength(), or public fields with those > > names, or implemented the GenericConfigurable interface. > > > > Similarly, the syntax for specifying a sequence globally via the > > openjpa.Sequence setting would look like so: > > > > > > > > OpenJPA configuration settings that can implement a particular > > interface use this format plus more-friendly aliases quite frequently. > > > > -Patrick > > > > On Nov 5, 2007 1:21 PM, Miroslav Nachev < > miro@space-comm.com> wrote: > > > > The implementation of Seq interface is the easiest part of the task. I > can > > not see how to configure JPA to use my Seq implementation instead of the > > standard. Can I do that with annotation or I have to use another tricks? > > > > > > Miro. > > > > On 11/5/07, Patrick Linskey > wrote: > > > > Gotcha. To do that, you'll need to implement the > > org.apache.openjpa.kernel.Seq interface. Take a look at the docs [1] > > for details. That section of the docs also has some examples that > > should help you use your custom sequence. > > > > [1] > > > http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_sequence > > > > -Patrick > > > > On Nov 5, 2007 1:01 PM, Miroslav Nachev < > miro@space-comm.com> wrote: > > > > No. I want to have my own class with which to generate the Ids. > > For example I have binary(32) field which is the Primary Key. I would > > > > like > > > > to generate the values for this PK in my own way. > > > > > > Miro. > > > > > > On 11/5/07, Patrick Linskey > wrote: > > > > Hi, > > > > Can you describe what you mean by a "generic" GeneratedValue? Do you > > mean that you'd like to use the @GeneratedValue annotation on > > non-identity fields? If so, then that is possible in OpenJPA. > > > > -Patrick > > > > On Nov 5, 2007 12:08 PM, Miroslav Nachev < > miro@space-comm.com> wrote: > > > > Hi, > > > > Is there any way to have Generic GeneratedValue in OpenJPA. I know > > > > that > > > > this > > > > is possible in Hibernate JPA but I would like to use OpenJPA if is > > > > possible. > > > > Any suggestions? > > > > > > Regards, > > Miro. > > > > -- > > Patrick Linskey > > 202 669 5907 > > > > -- > > Patrick Linskey > > 202 669 5907 > > > > > > > > > ------=_Part_15567_25535016.1198013876312--