Search code examples
javajpaobjectdb

Object db passing an Object as parameter


I have been using JSF, JPA and MySQL with EclipseLink for 5 years. I found that I want to shift to Object db as it is very fast specially with a very large dataset. During migration, I found this error. In JPA with EclipseLink, I passed objects as parameters. But in Object DB, I need to pass the id of objects to get the results. I have to change this in several places. Can enyone help to overcome this issue.

THis code worked fine with EclipseLink and MySQL. Here I pass the object"salesRep" as the parameter.

String j = "select b from "
            + " Bill b "
            + " where b.billCategory=:cat "
            + " and b.billType=:type "
            + " and b.salesRep=:rep ";
    Map m = new HashMap();
    m.put("cat", BillCategory.Loading);
    m.put("type", BillType.Billed_Bill);
    m.put("rep", getWebUserController().getLoggedUser());

I have to chage like this to make it work in ObjectDB.Here I have to pass the id (type long) of the object"salesRep" as the parameter.

String j = "select b from "
            + " Bill b "
            + " where b.billCategory=:cat "
            + " and b.billType=:type "
            + " and b.salesRep.id=:rep ";
    Map m = new HashMap();
    m.put("cat", BillCategory.Loading);
    m.put("type", BillType.Billed_Bill);
    m.put("rep", getWebUserController().getLoggedUser().getId());

Solution

  • There is a difference between EclipseLink and ObjectDB in handling detached entity objects. The default behaviour of ObjectDB is to follow the JPA specification and stop loading referenced objects by field access (transparent navigation) once an object becomes detached. EclipseLink does not treat detached objects this way.

    This could make a difference in situations such as in a JSF application, where an object becomes detached before loading all necessary referenced data.

    One solution (the JPA portable way) is to make sure that all the required data is loaded before objects become detached.

    Another possible solution is to enable loading referenced objects by access (transparent navigation) for detached objects, by setting the objectdb.temp.no-detach system property. See #3 in this forum thread.