Hi,
I use version 01.12 and the problem only happens when you change the schema with ALTER SESSION SET CURRENT_SCHEMA x .
The patch I have done on SDriverOracle looks like this:
/** Specializes SDriver.generateKey using Oracle SEQUENCEs. */
protected long generateKey(SRecordMeta rec, SFieldMeta keyFld) {
Object sequenceName = keyFld.getProperty(SSEQUENCE_NAME);
if (sequenceName == Boolean.FALSE)
return super.generateKey(rec, keyFld);
String qry = "SELECT " + (String)sequenceName + ".NEXTVAL FROM DUAL";
Object next = SConnection.rawQueryJDBC(qry);
// Begin PATCH
/*long db = ((Number)next).longValue();
return keyFld.nextGeneratedValue(db);*/
return((Number)next).longValue();
// End PATCH
}
The key is now always read from the oracle sequence. The internal counter lastGeneratedKeyValue in SFieldMeta is dangerous because it does not notice that the db-session was changed. Because after changing to another schema the driver is calling .nextval on a different sequence (but with the same name).
The default of SSEQUENCE_NAME is tablename_SEQ. Because my sequences are named like this I don't have to use this property in the constructor of the primary key in the subclass of SRecordInstance. To prefix the sequence name with the schema name does not solve th problem because if I call ALTER SESSION .... the correct sequence is called anyway.
You will run into troubles if you use your code while altering sessions back and forth.(If you use SDriverOracle)
It works now for me but I still don't know don't know why the SDriverOracle was implemented like this. Perhaps the implementor didn't took into account that sessions can be changed. So my patch would then perhaps be a bugfix for the next version of simpleORM(Or at least be worth a discussion).
regards,
oliver
-----Original Message-----
From: Linas Kavolius [mailto:linas <at> kada.lt]
Sent: Freitag, 9. Juli 2004 09:43
To: SimpleORM <at> yahoogroups.com
Subject: Re: [SimpleORM] Digest Number 318
Hello
I usualy use this description and it works well with henerated keys
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
package model;
import simpleorm.core.*;
import simpleorm.properties.*;
public class SVeiksmas extends SRecordInstance { // ie. a class mapped to a
table.
public static final SRecordMeta meta = new SRecordMeta(SVeiksmas.class,
"HIP.VEIKSMAI");
public static final SFieldInteger VEI_ID = new SFieldInteger (meta,
"VEI_ID",
new SPropertyValue[]{ SFD_PRIMARY_KEY, SFD_GENERATED_KEY,
SSEQUENCE_NAME.pvalue("HIP.hip_veiksmai_id_seq")});
public static final SFieldInteger VEIK_TIPAS = new
SFieldInteger(meta,"VEIK_TIPAS");
public SRecordMeta getMeta() { return meta; };
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
in what version you have nextGeneratedValue() on SFieldMeta from
SDriverOracle ?
Best regards,
Linas
----- Original Message -----
From: <SimpleORM <at> yahoogroups.com>
To: <SimpleORM <at> yahoogroups.com>
Sent: Friday, July 09, 2004 10:29 AM
Subject: [SimpleORM] Digest Number 318
>
> There is 1 message in this issue.
>
> Topics in this digest:
>
> 1. Why Call nextGeneratedValue() on SFieldMeta from SDriverOracle ?
> From: Oliver Eiholzer <Oliver.Eiholzer <at> steria.ch>
>
>
> ________________________________________________________________________
> ________________________________________________________________________
>
> Message: 1
> Date: Thu, 8 Jul 2004 11:55:27 +0200
> From: Oliver Eiholzer <Oliver.Eiholzer <at> steria.ch>
> Subject: Why Call nextGeneratedValue() on SFieldMeta from SDriverOracle ?
>
> Hi all,
>
> Does anyone know why the nextGeneratedValue() method on SFieldMeta is
called
> from SDriverOracle ?
> In my opinion this is not needed since oracle has sequences. Because the
> lastGeneratedKeyValue is cached by SFieldMeta is cached we have serious
> problems (ORA-00001 Unique Constraint violation).
>
> And that's how it happens:
> (Sequence starts with 1, increment 1)
>
> Steps
lastGeneratedKeyValue
> variable | CURRVAL of Sequence in Schema One | CURRVAL of Sequence in
Schema
> Two
> 0.
> 0 1
> 1
> 1. ALTER SESSION SET CURRENT_SCHEMA = One
> 2. Insert record 2
> 2 1
>
> 3. Insert record 3
> 3 1
> 4. ALTER SESSION SET CURRENT_SCHEMA = Two
> 5. Insert record 4!!
> 3 2
>
> 6. Restart Server
> 0 3
> 2
> 7. ALTER SESSION SET CURRENT_SCHEMA = Two
> 8. Insert record
> 3 3
> 3
> 9. Insert record -> Unique Constraint violation because
sequenceTwo.nextval
> returns 4 but dthis ID was already used on step 5.
>
> This code in SFieldMeta causes the troubles:
> synchronized long nextGeneratedValue(long minimum) {
> if (lastGeneratedKeyValue < minimum)
> lastGeneratedKeyValue = minimum;
> else
> ++lastGeneratedKeyValue;
> return lastGeneratedKeyValue;
> }
>
> Bevor I patch the SDriverOracle class i would like to know why it calls
the
> nextGeneratedValue() method.
>
> Any Ideas?
>
> regards,
>
> oliver
>
> -----Original Message-----
> From: Anthony & Melissa Berglas
> [mailto:berglas <at> SpreadsheetDetective.com]
> Sent: Mittwoch, 7. Juli 2004 06:37
> To: SimpleORM <at> yahoogroups.com
> Subject: Re: [SimpleORM] SFieldReference necessary
>
>
> Should be OK, but look at the examples to see how to do it correctly.
> You do not want to end up with fields declared twice.
>
> Anthony
>
> Alexander Banthien wrote:
>
> > Hi all,
> >
> > I just stumbled accros something and would like to hear I am on the
> > right track. I reverse engineered my classes from the DB using
> > SimpleORMGenerate. That tool does not at all create SFieldReferences but
> > only SFieldLongs (or whatever type the keys are) and autocodes getters
> > and setters to do the object navigation (Employee.getDepartment()). (as
> > documented in the corresponding package.html)
> >
> > Is it advisable to use SFieldReferences over plain fields or doesn't it
> > matter? (all assuming I don't intend to forward engineer my database
> > schema from the SimpleORM classes) Performace? stability? ...
> >
> > Alexander
> >
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
> [This message contained attachments]
>
>
>
> ________________________________________________________________________
> ________________________________________________________________________
>
>
>
> ------------------------------------------------------------------------
> Yahoo! Groups Links
>
>
>
>
> ------------------------------------------------------------------------
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/5cFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/SimpleORM/
<*> To unsubscribe from this group, send an email to:
SimpleORM-unsubscribe <at> yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
Yahoo! Groups Links