661 words

persistence.xml classes not respected by ObjectDB

#1
2013-08-20 07:48

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.

zmirc
zmirc's picture
Joined on 2013-05-03
User Post #33
#2
2013-08-20 12:50

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,634
#3
2013-08-21 09:16

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?

zmirc
zmirc's picture
Joined on 2013-05-03
User Post #34
#4
2013-08-21 15:12

<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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,636
#5
2013-08-21 15:34

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).

zmirc
zmirc's picture
Joined on 2013-05-03
User Post #35
#6
2013-08-26 08:04

Any solution / bug fix?

zmirc
zmirc's picture
Joined on 2013-05-03
User Post #36
#7
2013-08-26 08:12

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,643
#8
2013-09-01 08:53

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.

zmirc
zmirc's picture
Joined on 2013-05-03
User Post #37
#9
2013-09-01 09:48

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #1,656
#10
2013-09-01 10:53

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.

zmirc
zmirc's picture
Joined on 2013-05-03
User Post #38

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.
Attachments:
Maximum file size: 32 MB
Cancel