Home » Support » Forum » JDO sequences from ORM file

JDO sequences from ORM file


I want to use sequences in JDO without using annotations. Normally this is done with a package-X.orm file, where X is a value passed to the PersistenceManagerFactory as the value of property "mapping". I'm encouraged to see that the JDO zip that comes with ObjectDB includes the DTD/XSD for this type of file, though I can't see a mention of it in the manual.

But I've tried creating one as below and persistenceManager.getSequence("com.spiffymap.model.UserSequence") returns null as though it's not seeing it. Is this supported and if so what could I be doing wrong?

    <package name="com.spiffymap.model">
        <sequence name="UserSequence" strategy="TABLE"/>

It is supported, but not mentioned in the manual, because the new manual focuses on JPA (the old JDO manual covers only JDO 1.x, and this specific feature was added later).

It is included in our tests (that are part of every build), but in a package.jdo file rather than an orm file.

Maybe the problem is in loading the XML metadata? Can you check that other settings in that XML file affect? Could you try putting it in the ordinary package.jdo file?

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

I didn't think sequence was valid in a package.jdo file. I tried adding the following to package.jdo

<sequence name="UserSequence" strategy="contiguous" />

and getSequence() still returns null. The package.jdo file is definitely being read, because when I put strategy="TABLE" in there, the XML validation failed at enhance time.

How does it appear in the package.jdo file used for your tests?


See s1 below.

But the test uses an internal way to check for the sequence, rather than getSequence().

<?xml version="1.0" encoding="UTF-8" ?>

<jdo xmlns="http://java.sun.com/xml/ns/jdo/jdo"

<package name="com.objectdb.schema">

  <!-- Persistable Types -->
  <interface name="JdoTypes$PersistenceCapableInterface"
   requires-extent="true" embedded-only="false" />
  <class name="JdoTypes$PersistenceCapableClass" persistence-modifier="persistence-capable" />
  <class name="JdoTypes$AbstractPersistenceCapableClass" />
  <class name="JdoTypes$EmbeddedOnly1" embedded-only="true" />
  <class name="JdoTypes$EmbeddedOnly2" embedded-only="true" />
  <class name="JdoTypes$PersistenceCapableWithIdClass1" objectid-class="java.lang.String" />
  <class name="JdoTypes$PersistenceCapableWithIdClass2" objectid-class="javax.jdo.identity.IntIdentity" />
  <class name="JdoTypes$PersistenceCapableWithNoExtent" requires-extent="false" />
  <class name="JdoTypes$DetachablePersistenceCapable" detachable="true" />
  <class name="JdoTypes$NonDetachablePersistenceCapable" detachable="false" />
  <class name="JdoTypes$CacheableClass" cacheable="true" />
  <class name="JdoTypes$NonCacheableClass" cacheable="false" />

  <!-- Persistable Types with Indexes -->
  <class name="JdoTypes$PersistenceCapableWithIndex">
   <index name="i1" unique="false">
    <field name="path1" />
    <field name="path2" />
  <class name="JdoTypes$PersistenceCapableWithUnique">
   <unique name="i2">
    <field name="path1" />
  <class name="JdoTypes$PersistenceCapableWithIndices">
   <index name="i3" unique="false">
    <field name="path1" />
   <index unique="true">
    <field name="path2" />
  <class name="JdoTypes$PersistenceCapableWithUniques">
    <field name="path1" />
   <unique name="i4">
    <field name="path2" />

  <!-- Persistable Types with Fetch Groups -->
  <class name="JdoTypes$ClassWithFetchGroup">
   <fetch-group name="fg1" post-load="false">
    <fetch-group name="sg1" />
    <field name="p" recursion-depth="7" />
  <class name="JdoTypes$ClassWithFetchGroups">
   <fetch-group name="default">
    <field name="p1" />
   <fetch-group name="fg2">
    <field name="p2" />

  <!-- Persistable Types with Queries -->
  <class name="JdoTypes$ClassWithQuery">
   <query name="q1" language="ODBQL" unmodifiable="true" unique="true" result-class="java.lang.String">
    <extension vendor-name="objectdb" key="k" value="v" />
  <class name="JdoTypes$ClassWithQueries">
   <query name="q2">s2</query>
   <query name="q3">s3</query>

  <!-- Persistable Types with Sequence -->
  <class name="JdoTypes$ClassWithSequence" />

  <!-- For Exceptions - mismatch class / interface -->
  <interface name="ExceptionTest$ClassInterfaceMismatch" />

  <!-- Duplicate type (for coverage) -->
  <class name="JdoTypes$DummyDuplicate" />
  <class name="JdoTypes$DummyDuplicate" />
  <!-- The Sequence -->
  <sequence name="s1" factory-class="java.lang.Long" strategy="contiguous" />

<!-- Global Named queries -->
<query name="globalJdoQuery" language="JDOQL">DUMMY JDOQL QUERY</query>

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Thanks. I have got this working, by a combination of moving the sequence from ORM to JDO file, specifying the factory-class as above, and changing my fully-qualified sequence name (including the name of the package it's defined in) to use the unqualified name.

I don't think that's strictly compliant with the JDO standard - you're supposed to use the fully qualified name to prevent clashes between sequences of the same name in different packages. It's certainly different to any of the other JDO implementations I've used (Xcalia, Kodo, Versant and DataNucleus). But it's usable as it is, so thanks for your help.


Good that it works, and thank you for your comments.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Hello, unfortunately I've now discovered that it only works in one very rare circumstance, and doesn't work most of the time.

It turns out that specifiying and retrieving the Sequence is only working, as above, when accessing an ObjectDB file for the first time. If I access it for a second time, using exactly the same code (running the same junit test again), then this time getSequence() returns null.

I've tried increasing the logging level to "debug" in objectdb.conf, but sequences don't seem to be mentioned in the output.

For the same code to succeed or fail depending on the status of the odb file must be a bug in ObjectDB?


It could be a bug. Most ObjectDB users use JPA, so JDO features that are not covered by the JDO TCK or by our own JDO tests, may sometimes be broken, until someone needs them.

If you would like us to explore this issue, and fix it if necessary, please follow the posting instructions and post a test case that demonstrates the problem.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Build 2.4.7_04 should fix this problem. More details are discussed in issue 1074.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login