Title: Message
Yes, this is possibly BUG, i guess...
So, if you can - you may define trigger on insert in your SAB DB, then castor will not use key generator and you problem will be fixed.
You can also by using http://www.castor.org/javadoc/org/exolab/castor/persist/spi/KeyGenerator.html  and http://www.castor.org/javadoc/org/exolab/castor/persist/spi/KeyGeneratorFactory.html class create your own key gen based on http://www.castor.org/javadoc/org/exolab/castor/jdo/drivers/SequenceKeyGenerator.html
And use it by defining in castor.properties:
# List of key generator factories
#
org.exolab.castor.jdo.keyGeneratorFactories=\
  org.exolab.castor.jdo.drivers.MaxKeyGeneratorFactory,\
  org.exolab.castor.jdo.drivers.HighLowKeyGeneratorFactory,\
  org.exolab.castor.jdo.drivers.IdentityKeyGeneratorFactory,\
  org.exolab.castor.jdo.drivers.SequenceKeyGeneratorFactory,\
  org.exolab.castor.jdo.drivers.UUIDKeyGeneratorFactory
 
 
Now in SequenceKeyGenerator.java where is (in line 270):
  seqName = MessageFormat.format( _seqName, new String[] {tableName,primKeyName});
  nextval = _factory.quoteName(seqName + ".nextval");
And this result - quoted sequence name.
 
Thanks!
-----Original Message-----
From: michael simons [mailto:[EMAIL PROTECTED]
Sent: Monday, July 07, 2003 4:55 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Sequence and SAP-DB

Hi Alexey et al,

No, the resulting error message is "Missing constant".
I changed the statement a little so it ran successfully, so I can tell what's the bug:
SAP DB does not accept the quotes (") around the nextval function call
This way it worked:
INSERT INTO "PRODUCT_GROUP" ("ID", "NAME") VALUES ("PRODUCT_GROUP_SEQ".nextval, 'test')

So this is a bug, isn't it?

Regards,
Michael Simons

At 16:25 07.07.2003 +0400, you wrote:
Hi,
 
Can you run this SQL on DB side?
For ? parameter just enter some string value:
INSERT INTO "PRODUCT_GROUP" ("ID", "NAME") VALUES ("PRODUCT_GROUP_SEQ"."nextval", "test")
 
Thanks!
-----Original Message-----
From: michael simons [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 07, 2003 3:49 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Sequence and SAP-DB

Hello Alexey et al,

I did what You told me to do and here's what I've got:

[test] Error creating net.uniopt.jdo.example1.ProductGroup, SQL : INSERT INTO "PRODUCT_GROUP" ("ID","NAME") VALUES ("PRODUCT_GROUP_SEQ"."nextval",?)
net.uniopt.jdo.example1.ProductGroup:-1 becomes transient.
org.exolab.castor.jdo.PersistenceException: Nested error: com.sap.dbtech.jdbc.exceptions.DatabaseException: [-5004] (at 52): Missing constant
com.sap.dbtech.jdbc.exceptions.DatabaseException: [-5004] (at 52): Missing constant

As you can see in the first line there's obviously a failure in the SQL generated by Castor. So I guess it's a bug in Castor or in the SAP DB driver resp.

Do you agree?

Regards,
Michael Simons

At 12:59 03.07.2003 +0400, you wrote:
Hello Michael,
Unfortunally i haven't any expertise working with SAP DB and can't give you some realy tips. But, just one of workaround - is trace SQL posted by Castor to the DB and look at this. Then try run it directly on DB SQL manager.
How to set up Castor Logging you can see at:
http://www.brainopolis.com/castorwiki/Wiki.jsp?page=IntegratingLogging
Then you get SQL from Castor try to run it directly on SAP DB, if you get any errors, then misstake in SEQUECNCE on DB side, if not on is Castor problems, maybe within mapping or classes structure.
Good luck!
-----Original Message-----
From: michael simons [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 02, 2003 9:40 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Sequence and SAP-DB

Hi Alexey, et al,

still doesn't work. Now I get the following exception





org.exolab.castor.jdo.PersistenceException: Nested error: com.sap.dbtech.jdbc.exceptions.DatabaseException: [-5004] (at 52): Missing constant
com.sap.dbtech.jdbc.exceptions.DatabaseException: [-5004] (at 52): Missing constant

I've been testing with a simpler example this time, so mapping follows:

<mapping>
  <key-generator name="SEQUENCE" alias="PRODUCT_GROUP_SEQ">
    <param name="sequence" value="PRODUCT_GROUP_SEQ"/>
  </key-generator>
  <!--
    ** Mapping for ProductGroup
    -->
  <class name="net.uniopt.jdo.example1.ProductGroup" identity="id" key-generator="PRODUCT_GROUP_SEQ">
...

what am I doing wrong?

Regards,
michael

At 16:18 02.07.2003 +0400, you wrote:
Hello!
It becose you set parameter "trigger" to true
http://www.castor.org/key-generator.html#SEQUENCE-key-generator
you may set the "trigger" parameter to "true". This will prevent the "Sequence_name".nexval from being pulled twice (first time in the insert statement (see above), then in the trigger). Also usefull in combination with the "returning" parameter set to "true" for Oracle (in this case you may not specify the sequence name).
So, if you set trigger to true, you must set up insert trigger for your tables and generate ID in this trigger before insert. Castor will not try generate any keys in this case.
Good luck!
-----Original Message-----
From: michael simons [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 02, 2003 4:11 PM
To: [EMAIL PROTECTED]
Subject: [castor-dev] Sequence and SAP-DB
Hello,

Does anybody know whether key generating by sequence works w/ SAP-DB?

I tried by the following in my mapping file but when running the program I always get a NotNull exception for the id field (i.e. the primary key "id" was not set)

<begin mapping.xml>
...
<key-generator name="SEQUENCE">
<param name="sequence" value="stromboli"/>
<param name="trigger" value="true"/>
</key-generator>
...
<class name="net.uniopt.biz.sys.Language" extends="net.uniopt.data.DataObject" identity="id" key-generator="SEQUENCE">
...
<end mapping.xml>

Regards,
michael

Reply via email to