Hi,
I'm a bit confused about a strange behavior of my JPA's related objects.
I have three bundle :
The User bundle does contain some user-related objects, but mainly the User object.
The Energy bundle does contain some energy-related objects, and particularly a ConsumptionTerminal which contains a List of User.
The Index bundle does contain an Index object that has no dependency at all.
My OSGi environment is the following :
A DataSource bundle that provide 2 services : dataSource and jpaVendorAdapter.
The three bundles. They consume dataSource and jpaVendorAdapter.
Their module-context.xml file look like :
And they all have a persistence.xml file :
User
<?xml version="1.0" encoding="UTF-8"?>
<persistence>
<persistence-unit name="securityPU" transaction-type="JTA">
<jta-data-source>java:/securityDataSourceService</jta-data-source>
<class>net.nextep.amundsen.security.domain.User</class>
<!-- [...] -->
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level" value="INFO" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.orm.throw.exceptions" value="true" />
</properties>
</persistence-unit>
</persistence>
Energy
<?xml version="1.0" encoding="UTF-8"?>
<persistence>
<persistence-unit name="energyPU" transaction-type="JTA">
<jta-data-source>java:/securityDataSourceService</jta-data-source>
<class>net.nextep.amundsen.security.domain.User</class>
<class>net.nextep.amundsen.energy.domain.User</class>
<!-- [...] -->
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level" value="INFO" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.orm.throw.exceptions" value="true" />
</properties>
</persistence-unit>
</persistence>
Index : This one has the most simple persistence.xml with just the Index class (no shared Class).
I'm using named @PersistenceUnit annotation like @PersitenceUnit(name = 'securityPU') (for the User bundle).
And finally, I'm using EclipseLink as Jpa provider and Spring DM (+ Spring DM Server in the development process)
The problem is the following :
When the User bundle is deployed, I'm able to persist User objects.
When the User bundle and Energy bundles are both deployed, I'm not able to persist User objects (neither the Energy object). But I don't have any exception at all !
There is no problem at all with the Index bundle.
The bug is dataSource independent (I tried with PostgreSQL and MySQL so far).
My first conclusion was that the <class>net.nextep.amundsen.security.domain.User</class> in both persistence unit was causing the trouble. I tried without it (and hiding the User dependent object in the Energy bundle) but it failed too.
I'm a bit confused about that bug. I'm also not quite sure about the transaction management in this context.
I wasn't the one who designed this architecture (but I tell my intern OK without testing it.. shame on me) but if I could understand this bug and maybe fix it without rewrite the bundle (and break my intern work), I would appreciate. Am I doing something wrong ? (it's obvious, but what..) Did I miss something while reading documentation ?
By the way, I'm also looking for some best practices or advices when it comes to JPA, EclipseLink (or whatever JPA Provider) and Spring DM (and OSGi in general). I found interesting slides from Mike Keith about this topic (by browsing Stackoverflow).