Home » Support » Forum » JDO sequences from ORM file

JDO sequences from ORM file

#1

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?

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

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)
#3

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?

#4

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>
<!--       
<jdo xmlns="http://java.sun.com/xml/ns/jdo/jdo"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/jdo/jdo
        http://java.sun.com/xml/ns/jdo/jdo_2.xsd">
-->

<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" />
   </index>
  </class>
  <class name="JdoTypes$PersistenceCapableWithUnique">
   <unique name="i2">
    <field name="path1" />
   </unique>
  </class>
  <class name="JdoTypes$PersistenceCapableWithIndices">
   <index name="i3" unique="false">
    <field name="path1" />
   </index>
   <index unique="true">
    <field name="path2" />
   </index>
  </class>
  <class name="JdoTypes$PersistenceCapableWithUniques">
   <unique>
    <field name="path1" />
   </unique>
   <unique name="i4">
    <field name="path2" />
   </unique>
  </class>

  <!-- 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" />
   </fetch-group>
  </class>
  <class name="JdoTypes$ClassWithFetchGroups">
   <fetch-group name="default">
    <field name="p1" />
   </fetch-group>
   <fetch-group name="fg2">
    <field name="p2" />
   </fetch-group>
  </class>

  <!-- 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" />
    select
   </query>
  </class>
  <class name="JdoTypes$ClassWithQueries">
   <query name="q2">s2</query>
   <query name="q3">s3</query>
  </class>

  <!-- 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" />
</package>

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

</jdo>
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#5

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.

#6

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

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

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?

#8

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)
#9

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