You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by gollum <ch...@gmail.com> on 2013/03/17 16:54:08 UTC

@MappedSuperclass & persistence.xml

Hi all,
I have a question regarding the use of the JPA @MappedSuperclass annotation
in a TomEE+ 1.5.1 environment. I'll describe it with this minimal
configuration:

*@MappedSuperclass*
public abstract class AbstractSuperclass implements Serializable {
    @Id
    @GeneratedValue
    protected Long id;
    ...
}

*@Entity*
public class Subclass extends AbstractSuperclass {
    @Column
    private String name;
}

*persistence.xml*
<persistence-unit name="test_pu" transaction-type="JTA">
   
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <jta-data-source>jdbc/Test</jta-data-source>
    <non-jta-data-source>jdbc/TestNonJTA</non-jta-data-source>
    <properties>
        <property name="openejb.jpa.init-entitymanager" value="true" />
        <property name="openejb.jpa.auto-scan" value="true" />
        <property name="openejb.jpa.auto-scan.package"
value="de.mdesign.hellorest.entity" />
        <property name="openjpa.RuntimeUnenhancedClasses"
value="unsupported" />
        <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
    </properties>
</persistence-unit>

This actually fails on deployment as the Sublass cannot be loaded. Here is
what the log says:  http://pastebin.com/Muw6tKDt
<http://pastebin.com/Muw6tKDt>  

However, when I explicitly declare the entity classes in the
persistence.xml, everything is fine:

*persistence.xml (with entity declarations)*
<persistence-unit name="test_pu" transaction-type="JTA">
   
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <jta-data-source>jdbc/Test</jta-data-source>
    <non-jta-data-source>jdbc/TestNonJTA</non-jta-data-source>
    *<class>de.mdesign.hellorest.entity.Subclass</class>*
    *<class>de.mdesign.hellorest.entity.AbstractSuperclass</class>*
    <properties>
        <property name="openejb.jpa.init-entitymanager" value="true" />
        <property name="openejb.jpa.auto-scan" value="true" />
        <property name="openejb.jpa.auto-scan.package"
value="de.mdesign.hellorest.entity" />
        <property name="openjpa.RuntimeUnenhancedClasses"
value="unsupported" />
        <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
    </properties>
</persistence-unit>

Is it possible that the auto-scan ignores classes decorated with
@MappedSuperclass and as a side effect of that openjpa fails loading
entities inheriting from that class ?



--
View this message in context: http://openejb.979440.n4.nabble.com/MappedSuperclass-persistence-xml-tp4661568.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: @MappedSuperclass & persistence.xml

Posted by gollum <ch...@gmail.com>.
Wow, that was fast! Thanks for the update Romain.



--
View this message in context: http://openejb.979440.n4.nabble.com/MappedSuperclass-persistence-xml-tp4661568p4661570.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: @MappedSuperclass & persistence.xml

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

yes, same for embeddable. That's fixed on trunk

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/3/17 gollum <ch...@gmail.com>

> Hi all,
> I have a question regarding the use of the JPA @MappedSuperclass annotation
> in a TomEE+ 1.5.1 environment. I'll describe it with this minimal
> configuration:
>
> *@MappedSuperclass*
> public abstract class AbstractSuperclass implements Serializable {
>     @Id
>     @GeneratedValue
>     protected Long id;
>     ...
> }
>
> *@Entity*
> public class Subclass extends AbstractSuperclass {
>     @Column
>     private String name;
> }
>
> *persistence.xml*
> <persistence-unit name="test_pu" transaction-type="JTA">
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>     <jta-data-source>jdbc/Test</jta-data-source>
>     <non-jta-data-source>jdbc/TestNonJTA</non-jta-data-source>
>     <properties>
>         <property name="openejb.jpa.init-entitymanager" value="true" />
>         <property name="openejb.jpa.auto-scan" value="true" />
>         <property name="openejb.jpa.auto-scan.package"
> value="de.mdesign.hellorest.entity" />
>         <property name="openjpa.RuntimeUnenhancedClasses"
> value="unsupported" />
>         <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)" />
>     </properties>
> </persistence-unit>
>
> This actually fails on deployment as the Sublass cannot be loaded. Here is
> what the log says:  http://pastebin.com/Muw6tKDt
> <http://pastebin.com/Muw6tKDt>
>
> However, when I explicitly declare the entity classes in the
> persistence.xml, everything is fine:
>
> *persistence.xml (with entity declarations)*
> <persistence-unit name="test_pu" transaction-type="JTA">
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>     <jta-data-source>jdbc/Test</jta-data-source>
>     <non-jta-data-source>jdbc/TestNonJTA</non-jta-data-source>
>     *<class>de.mdesign.hellorest.entity.Subclass</class>*
>     *<class>de.mdesign.hellorest.entity.AbstractSuperclass</class>*
>     <properties>
>         <property name="openejb.jpa.init-entitymanager" value="true" />
>         <property name="openejb.jpa.auto-scan" value="true" />
>         <property name="openejb.jpa.auto-scan.package"
> value="de.mdesign.hellorest.entity" />
>         <property name="openjpa.RuntimeUnenhancedClasses"
> value="unsupported" />
>         <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)" />
>     </properties>
> </persistence-unit>
>
> Is it possible that the auto-scan ignores classes decorated with
> @MappedSuperclass and as a side effect of that openjpa fails loading
> entities inheriting from that class ?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/MappedSuperclass-persistence-xml-tp4661568.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>