ObjectDB ObjectDB

persistence.xml classes not respected by ObjectDB

#1

Hi!

I have the following persistence.xml. The problem is that ObjectDB loads all the classes in P1 (+ their embeddable classes). P2 is created properly, but P1 gets all entity classes (from P2 also). How can this be avoided, so that both P1 and P2 get just the classes that were specified to each?

There is no place in code where P1 tries to access classes from P2, so it makes no sense.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="P1" transaction-type="JTA">
    <provider>com.objectdb.jpa.Provider</provider>
    <class>com.pingushare.entity.p1.Item</class>
    <class>com.pingushare.entity.p1.Login</class>
    <class>com.pingushare.entity.p1.Trade</class>
    <class>com.pingushare.entity.p1.TradeRequest</class>
    <class>com.pingushare.entity.p1.User</class>
    <class>com.pingushare.entity.p1.Wish</class>
    <shared-cache-mode>NONE</shared-cache-mode>
    <validation-mode>NONE</validation-mode>
    <properties>
      <property name="javax.persistence.jdbc.url" value="objectdb://localhost/xxx/p1.odb"/>
      <property name="javax.persistence.jdbc.user" value="xxx"/>
      <property name="javax.persistence.jdbc.password" value="xxx"/>
    </properties>
  </persistence-unit>
  <persistence-unit name="P2" transaction-type="JTA">
    <provider>com.objectdb.jpa.Provider</provider>
    <class>com.pingushare.entity.p2.Email</class>
    <class>com.pingushare.entity.p2.EmailActivation</class>
    <class>com.pingushare.entity.p2.PasswordReset</class>
    <shared-cache-mode>NONE</shared-cache-mode>
    <validation-mode>NONE</validation-mode>
    <properties>
      <property name="javax.persistence.jdbc.url" value="objectdb://localhost/xxx/p2.odb"/>
      <property name="javax.persistence.jdbc.user" value="xxx"/>
      <property name="javax.persistence.jdbc.password" value="xxx"/>
    </properties>
  </persistence-unit>
</persistence>

Thanks.

edit
delete
#2

Try adding <exclude-unlisted-classes/> after the list of classes:

<persistence-unit name="P2" transaction-type="JTA">
  <provider>com.objectdb.jpa.Provider</provider>
  <class>com.pingushare.entity.p2.Email</class>
  <class>com.pingushare.entity.p2.EmailActivation</class>
  <class>com.pingushare.entity.p2.PasswordReset</class>
  <exclude-unlisted-classes/>
  <shared-cache-mode>NONE</shared-cache-mode>
  <validation-mode>NONE</validation-mode>
  <properties>
    <property name="javax.persistence.jdbc.url" value="objectdb://localhost/xxx/p2.odb"/>
    <property name="javax.persistence.jdbc.user" value="xxx"/>
    <property name="javax.persistence.jdbc.password" value="xxx"/>
  </properties>
</persistence-unit>
ObjectDB Support
edit
delete
#3

I'm afraid that it doesn't do it.

I have already tried a couple of times.

The lucky part is that I have the old DB on my development machine. By adding class by class into that one, it seems that they ODB didn't merge all classes, as it does if I erase the DB and start all over.

But that's a problem. I have discovered it when I had to delete and set the new database in production. It just didn't want to respect the restrictions. I had to delete the elements in the development db, then upload the files on production, then start the app. Otherwise I can't do it.

What is it to be done?

edit
delete
#4

<exclude-unlisted-classes/> will not delete classes that are already in the database. It should, however, prevent automatic registration of classes that the application doesn't use.

But if the application tries to use a specific class explicitly, it may be loaded even if <exclude-unlisted-classes/> is specified.

We should be able to explore this further if you provide a minimal example that demonstrates the problem.

ObjectDB Support
edit
delete
#5

I didn't say I want that feature to delete the classes. The problem is that ODB creates too many when a new database is used (so the db files are deleted before starting).

The application doesn't use the classes from P2 in P1. Take as a proof the fact that they don't appear in the development DB, the DB that got added class by class, as development went by.

Providing an example is a little bit more problematic, because it's already a very big project.

So, the bottom line is that ODB seems to do not respect the restriction when a fresh DB is created (created when the application starts).

edit
delete
#6

Any solution / bug fix?

edit
delete
#7

In our tests <exclude-unlisted-classes/> works and prevents loading unspecified classes.

If there is a bug and it could be demonstrated by a sample application, we will look for a fix.

ObjectDB Support
edit
delete
#8

Finally! This problem doesn't appear anymore.

It seems that <exclude-unlisted-classes>true</exclude-unlisted-classes> is the one that works.

Using just <exclude-unlisted-classes/> doesn't help at all.

edit
delete
#9

Good to hear that the problem doesn't appear anymore. However, until now, ObjectDB only checked if the exclude-unlisted-classes element exists, so specifying true, false or no value at all made no difference. There must be something else that made the change in your application.

But we see now that actually this is not the right behavior, only <exclude-unlisted-classes>true</exclude-unlisted-classes> should exclude unlisted classes, so this will be changed starting next build.

It should not affect your application, since you are already using this.

ObjectDB Support
edit
delete
#10

I'm pretty sure it was this, because I've just done some test today, before posting.

Anyway, I'm happy that now it seems to work.

edit
delete

Reply

To post on this website please sign in.