656 words

Conflicting modifiers .... (javax.persistence.Id, javax.persistence.ManyToOne)

2011-09-23 10:36

I have two classes a Container type class and another class that is 'contained' by that class.
The contained class, CompoundKeyMapItem, represents an alternate implementation of an object held in a Map, and uses a Compound Primary Key.
The contained class therefore uses an @IdClass.
This all works fine on Eclipselink.
However when I try and run this in ObjectDb I get the following error;

Problem Creating Database
[ObjectDB 2.2.9_05] javax.persistence.PersistenceException
Conflicting modifiers for field uk.co.his.experiment8.cmdline.objdb.CompoundKeyMapItem.container (javax.persistence.Id, javax.persistence.ManyToOne) (error 322)
at com.objectdb.jpa.EMImpl.persist(EMImpl.java:376)
at uk.co.his.experiment8.cmdline.objdb.Container.mapItemsPutNew(Container.java:64)
at uk.co.his.experiment8.cmdline.objdb.Container.generateMapItems(Container.java:54)
at uk.co.his.experiment8.cmdline.CreateDatabaseTestObjOnObjectDb.main(CreateDatabaseTestObjOnObjectDb.java:18)
Caused by: com.objectdb.o.UserException: Conflicting modifiers for field uk.co.his.experiment8.cmdline.objdb.CompoundKeyMapItem.container (javax.persistence.Id, javax.persistence.ManyToOne)
at com.objectdb.o.MSG.d(MSG.java:61)
at com.objectdb.o.JPA.d(JPA.java:385)
at com.objectdb.o.SCM.r(SCM.java:258)
at com.objectdb.o.TYS.n(TYS.java:282)
at com.objectdb.o.TYM.ae(TYM.java:512)
at com.objectdb.o.TYM.ac(TYM.java:458)
at com.objectdb.o.TYM.ao(TYM.java:777)
at com.objectdb.o.TYM.at(TYM.java:862)
at com.objectdb.o.TYM.aw(TYM.java:934)
at com.objectdb.o.OBM.bv(OBM.java:361)
at com.objectdb.o.OBM.bv(OBM.java:249)
at com.objectdb.jpa.EMImpl.persist(EMImpl.java:373)
... 3 more

What am I doing wrong?


import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.FlushModeType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Query;
import javax.persistence.Version;
import uk.co.his.experiment8.common.TestException;
  @NamedQuery(name = "numberOfMapItems", query = "SELECT COUNT(x) FROM CompoundKeyMapItem x") })
public class Container  {
public static Container getInstance(EntityManager em) {
  Container c = em.find(Container.class, "1");
  if (c == null) {
   c = new Container();
  return c;
protected String id = "1";
// used by JPA
private int version;
protected java.lang.Integer lastInstanceInMap;
protected Container() { // Empty constructor for JPA
public void generateMapItems(Integer numberToGen, EntityManager em)
   throws TestException {
  if (lastInstanceInMap == null) {
   lastInstanceInMap = 0;
  int endCnt = lastInstanceInMap + numberToGen;
  int startCnt = lastInstanceInMap;
  while (endCnt > startCnt) {
   mapItemsPutNew("" + startCnt, new CompoundKeyMapItem(startCnt), em);
   lastInstanceInMap = startCnt;
private CompoundKeyMapItem mapItemsPutNew(java.lang.String key,
   CompoundKeyMapItem newObj, EntityManager em) throws TestException {
  return newObj;
public CompoundKeyMapItem getMapItem(Integer cachedKey, EntityManager em) {
  return em.find(CompoundKeyMapItem.class, new CompoundKeyMapItem.CompoundKeyMapItemId(cachedKey.toString(), id));
public Integer getLastMapInstanceKey() {
  return lastInstanceInMap;
public int getNumberOfMapItems(EntityManager em) {
  Query q = em
  try {
   long l = (Long) q.getSingleResult();
   if (l > Integer.MAX_VALUE)
    return -1;
   int i = (int) l;
   return i;
  } catch (javax.persistence.NoResultException ex) {
   return -1;
mport java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.ManyToOne;
import javax.persistence.Version;
public class CompoundKeyMapItem  {
public static class CompoundKeyMapItemId implements Serializable {
  private static final long serialVersionUID = 0L;
  private String cachedKey;
  private String container;
  public CompoundKeyMapItemId() {}
  public CompoundKeyMapItemId(String id, String parent) {
   this.cachedKey = id;
   this.container = parent;
  public boolean equals(Object o) {
   if(!(o instanceof CompoundKeyMapItemId)) return false;
   CompoundKeyMapItemId other = (CompoundKeyMapItemId) o;
   return container.equals(other.container) && cachedKey.equals(other.cachedKey);
  public int hashCode() {
   //Follow bloch Item 8.
   int result = 17;
   result = 37*result + cachedKey.hashCode();
   result = 37*result + container.hashCode();
   return result;
  public String getCachedKey() {
   return cachedKey;
  public String getSingleton() {
   return container;
private Container container;
private String cachedKey
private int version;
private Integer property;
@SuppressWarnings("unused") //JPA
private CompoundKeyMapItem() {
public CompoundKeyMapItem(int startCnt) {
  property = startCnt;
public void setUUID() {
  //Do nothing we do not have a separate ID
public Integer getJPAVersion() {
  return version;
public void setSingleton(Container singleton) {
  this.container = singleton;
public void setCachedKey(String key) {
  this.cachedKey = key;
public String getCachedKey() {
  return cachedKey;
public void setProperty(Integer newValue) {
  property = newValue;
public Integer getProperty() {
  return property;
public String getInfo() {
  return "CompoundKeyMapItem: id=" + container.id + "/" + cachedKey + ", version=" + version + ", key=" + cachedKey + ", property=" + property;
public static void main(String[] args) throws IOException {
System.out.println("Creating Database TestObj on ObjectDb");
  javax.persistence.EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("TestObjPU");
  javax.persistence.EntityManager em = emf.createEntityManager();
  Container container = Container.getInstance(em);
  container.generateMapItems(1, em);
  System.out.println("Created Database");
catch(Throwable t)
  System.out.println("Problem Creating Database");
JFK's picture
Joined on 2011-08-24
User Post #13
2011-09-23 12:22

This validation check causes more trouble than it's worth.

It was removed in a new build - 2.3.0_01. Please try it.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support's picture
Joined on 2010-05-03
User Post #625

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Maximum file size: 32 MB