You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Jonathan Gallimore <jo...@gmail.com> on 2019/07/24 10:11:06 UTC

CMP/JPA/ORM code

Hi folks

I did a little simplification of this code so it simply uses a resource
finder from XBean, and uses the appModule's classloader.
https://github.com/apache/tomee/commit/76463ffb883ef7648b5efab8d28ff42cee03f00b.
If you see or run into any issues, please let me know.

Jon

Re: CMP/JPA/ORM code

Posted by Jonathan Gallimore <jo...@gmail.com>.
There's been a few PRs that have been merged in over the last few months in
this area, but I suspect the actual changes aren't too big.

For those reading who aren't familiar with this code, TomEE supports EJB
2.1 Entity beans, but does so in what I think is a very unique way (and I
can't take credit for any of it, by the way. I believe Dain wrote it long
before I joined the project). Effectively, what we do is read your entity
beans and your deployment descriptors, and we generate JPA classes and a
JPA ORM deployment descriptor and hand that off to a JPA provider to do the
actual persistence work. So your code might be EJB 2.1, but under the hood
it actually runs a JPA. Some side benefits of this are that it could
potentially be used to aid migration. In fact back in about 2008 I used
this code to try and do that in an Eclipse plugin.

One little trick is that this code defines a persistence unit called "cmp",
and adds its JPA entities there. You can actually define the CMP
persistence unit yourself and provide your own ORM.xml descriptor if you
wish. TomEE will try and merge in any definitions from your ejb-jar.xml
file that you don't include. A simple use case for this might be that you
want to customize the width of a varchar column for example. Another
usecase is that Hibernate doesn't work with what it generated - but
actually, provided your code isn't too complex, you can alter the generated
ORM.xml and make it work with Hibernate (and there's an Arquillian test in
this change that does exactly that).

There were a handful of issues with this code, including a provided custom
ORM xml file clashing with the generated one, or the same <mapping-file>
element being added to the CMP persistence unit when it already existed,
and the content of existing mapping files not being taken into account when
generating the ORM.xml.

I'll pull up the actual changes and write it up here in more detail for
everyone's benefit. Documentation-wise, I think we still lack something
that explains how all this works. I'm happy to take a take to write that up.

Jon

On Fri, Jul 26, 2019 at 12:39 AM David Blevins <da...@gmail.com>
wrote:

> > On Jul 24, 2019, at 3:11 AM, Jonathan Gallimore <
> jonathan.gallimore@gmail.com> wrote:
> >
> > I did a little simplification of this code so it simply uses a resource
> > finder from XBean, and uses the appModule's classloader.
> >
> https://github.com/apache/tomee/commit/76463ffb883ef7648b5efab8d28ff42cee03f00b
> .
> > If you see or run into any issues, please let me know.
>
> Great to see a test case in that PR!
>
> In the spirit of knowledge transfer, what makes that fix important?  Also,
> what documentation would you say might be missing to cover all the latest
> CMP work?
>
>
> -David
>
>

Re: CMP/JPA/ORM code

Posted by David Blevins <da...@gmail.com>.
> On Jul 24, 2019, at 3:11 AM, Jonathan Gallimore <jo...@gmail.com> wrote:
> 
> I did a little simplification of this code so it simply uses a resource
> finder from XBean, and uses the appModule's classloader.
> https://github.com/apache/tomee/commit/76463ffb883ef7648b5efab8d28ff42cee03f00b.
> If you see or run into any issues, please let me know.

Great to see a test case in that PR!

In the spirit of knowledge transfer, what makes that fix important?  Also, what documentation would you say might be missing to cover all the latest CMP work?


-David