Home » Support » Forum » Package name for persisted entities

Package name for persisted entities

#1

Hi,

I have a question about package name and searching for entities. As for now we were using two different databases for two different parts of our system. But we want to make a 'common' model for both systems. After merging entities from two different projects, we get single jar with all entities. Unfortunately some of the names are the same for entities:

- homplex.model.dbobject.Inspiration

- pl.hplxtool.model.Inspiration

The same for some other classes. Now the problem is that even if I specify full name with package in persistence.xml and set "exclude-unlisted-classes" for true, ODB is looking for first occurrence of 'Inspiration' class in database. In my case this is homplex.model.dbobject.Inspiration which is from another application and there is no objects stored using this class.

So my question is - is it possible to match entity name using full canonical name instead of only entity / class name? Or maybe it's a bug? Or maybe there is a way to set something like 'default-package-for-entities' in persistence.xml so I can set where ODB should look first for entity classes?

#2

JPA doesn't allow using the same entity name for more than one entity class. By default the entity name is the unqualified name of the class (class name without package name), but you can solve collision by specifying entity names explicitly.

You may also specify fully qualified class names in queries when using ObjectDB, since this is allowed in JDO:

SELECT i FROM homplex.model.dbobject.Inspiration

In JDO you even have an IMPORT clause in queries that you can use:

SELECT FROM Inspiration IMPORT homplex.model.dbobject.*

and ObjectDB supports it also in JPQL queries.

But this is per query - you cannot specify a preferred import more globally.

Finally, consider renaming classes by using the schema configuration.

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

Post Reply

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