Hello,

I am trying create my custom KeyGenerator wich will use stored procedure of
one big old project...

To begin I want to clone an existing KeyGenerator MaxKeyGenerator by giving
him the new name MinKeyGenerator,
and call it "MIN" in the mapping file.

For this purpose I have made the following :

I cloned MaxKeyGenerator to MinKeyGenerator:

1) I copied:
org.exolab.castor.jdo.drivers.MaxKeyGenerator ->
org.exolab.castor.jdo.drivers.MinKeyGenerator;
org.exolab.castor.jdo.drivers.MaxKeyGeneratorFactory ->
org.exolab.castor.jdo.drivers.MinKeyGeneratorFactory

2) I modified:
method MinKeyGeneratorFactory.getName() now returns "MIN" ...
---------------
    public String getName() {
        return "MIN";
    }
---------------
all other methods and properties I less like in MaxKeyGeneratorFactory and
MaxKeyGenerator...

3) I added a MaxKeyGeneratorFactory to the file castor.properties:
----------------
# List of key generator factories
org.exolab.castor.jdo.keyGeneratorFactories=\
  org.exolab.castor.jdo.drivers.MinKeyGeneratorFactory,\
  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,\
----------
I successefully compiled project and added MinKeyGenerator.jar to the
project ...
also I removed files (castor.properties) from (castor-0.9.4.jar) and
(castor-0.9.4-xml.jar)...

----------
I changed the name of key-generator MAX to MIN in mapping file of the
working application...
<mapping>
<class name="facastor15.Emprunt" identity="IdEmprunt" key-generator="MIN">
<map-to table="Emprunt" xml="Emprunt"/>
---------
And now then I start my application I have an Exception:

Castor: Creating facastor15.Emprunt (null)
org.exolab.castor.jdo.PersistenceException: Cannot create object of type
facastor15.Emprunt with null identity field and no key generator
org.exolab.castor.jdo.PersistenceException: Cannot create object of type
facastor15.Emprunt with null identity field and no key generator
 at org.exolab.castor.jdo.engine.SQLEngine.create(Unknown Source)
 at org.exolab.castor.persist.ClassMolder.create(Unknown Source)
 at org.exolab.castor.persist.LockEngine.create(Unknown Source)
 at org.exolab.castor.persist.TransactionContext.create(Unknown Source)
 at org.exolab.castor.jdo.engine.DatabaseImpl.create(Unknown Source)
 at facastor15.ImportExport.createEmprunt(ImportExport.java:224)
 at facastor15.ImportExport.run(ImportExport.java:278)
 at facastor15.ImportExport.main(ImportExport.java:50)

-----------
the same exception I have if I change the key-generator="MIN" to any not
existing key-generator name...
encore
What I do wrong ???
May be I have to change some properties file ...

The source files and jar you can find in attach.

Help me, Please.
And forgive me for my bad english.

Attachment: MinKeyGenerator.jar
Description: Binary data

Attachment: src.zip
Description: Binary data

Reply via email to