ObjectDB ObjectDB

Issue #633: Issues with JDO Casting & Full Qualified Names

Type: Bug ReoprtPriority: NormalStatus: ClosedReplies: 1
#1

Hi,

As I've feared.. Fully Qualified Names in casting not working, throws an identifier expected exception:

package com.test;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public final class F328
{

public static void main(String[] args)
{
  EntityManagerFactory emf = Persistence.createEntityManagerFactory("objectdb:$objectdb/db/test4.tmp;drop");
  EntityManager em = emf.createEntityManager();

  em.getTransaction().begin();
  MyEntity entity = new MyEntity();
  entity.embeddeds.put("test", new EmbeddedA());
  entity.embeddeds.put("test2", new EmbeddedB());
  em.persist(entity);
  em.getTransaction().commit();

  // FAIL WITH EXCEPTION HERE
  query = "SELECT COUNT(e) FROM MyEntity e WHERE ((com.test.F328.EmbeddedB)e.embeddeds.get('test2')).superB = '123'";
  System.out.println("4: " + em.createQuery(query).getSingleResult());

  em.close();
  emf.close();
}


@Entity
public static final class MyEntity
{
  Map<String, EmbeddedBase> embeddeds = new HashMap<String, EmbeddedBase>();
}


@Embeddable
public static class EmbeddedBase
{
  String base = "TEST";
}


@Embeddable
public static class EmbeddedA extends EmbeddedBase
{
  String name = "Alex";
}


@Embeddable
public static class EmbeddedB extends EmbeddedA
{
  String superB = "123";
}
}

Please any help.. I am starting to get really annoyed with all that map related workaround and stuff...

thanks very much!!!

Alex

edit
delete
#2

The problem is only with inner classes, which are not expected to be supported by JDO.

Try:

package com.test;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public final class F332
{

    public static void main(String[] args)
    {
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory(
                "objectdb:$objectdb/db/test4.tmp;drop");
        EntityManager em = emf.createEntityManager();

        em.getTransaction().begin();
        MyEntity entity = new MyEntity();
        entity.embeddeds.put("test", new EmbeddedA());
        entity.embeddeds.put("test2", new EmbeddedB());
        em.persist(entity);
        em.getTransaction().commit();

        // FAIL WITH EXCEPTION HERE
        String query = "SELECT COUNT(e) FROM MyEntity e " +
            "WHERE ((com.test.EmbeddedB)e.embeddeds.get('test2')).superB = '123' ";
        System.out.println("4: " + em.createQuery(query).getSingleResult());

        em.close();
        emf.close();
    }
}


@Entity
final class MyEntity
{
    Map<String, EmbeddedBase> embeddeds = new HashMap<String, EmbeddedBase>();
}


@Embeddable
class EmbeddedBase
{
    String base = "TEST";
}


@Embeddable
class EmbeddedA extends EmbeddedBase
{
    String name = "Alex";
}


@Embeddable
class EmbeddedB extends EmbeddedA
{
    String superB = "123";
}
ObjectDB Support
edit
delete

Reply

To post on this website please sign in.