Eclipselink, @OneToMany does not work with schema-generation = drop-and-create

110 views Asked by At

After much research , I finally found the cause of failure.

With Eclipselink, @OneToMany does not work (return null) when persistence.xml contains:

(drop-and-create)

<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>

But it works well with this:

(none)

<property name="javax.persistence.schema-generation.database.action" value="none"/>

Here are all the code of the file persistence.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" >
  <persistence-unit name="XXXX-ejbPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/xxxxDatasource</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>ALL</shared-cache-mode>
    <properties>
      <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
      <property name="eclipselink.target-database" value="MySQL"/>
      <property name="eclipselink.logging.level.sql" value="OFF"/>
      <property name="eclipselink.logging.parameters" value="true"/>
      <property name="eclipselink.persistence-context.flush-mode" value="AUTO"/>
    </properties>
  </persistence-unit>
</persistence>

P.S: @OneToMany works correctly with Hibernate.

Does anyone have a solution to this problem?

0

There are 0 answers