You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Dain Sundstrom <da...@iq80.com> on 2007/01/01 00:12:56 UTC
Generation of entity classes
I working on an implementation of the EJB cmp specification which
uses JPA under the covers to implement the persistence. I have the
basics working with hand written subclasses of the abstract cmp2
beans. I just wrote a code generator to replace my hand coded
subclasses using ASM (which rocks), and I am having problems getting
OpenJPA to enhance my generated class. It appears that at the moment
I construct the EMF all entity classes must be available via the temp
class loader. If they are not, OpenJPA will not add an entry into
the MetaData repository. Later when I generate my class and load it,
the OpenJPA transformer looks for the MetaData in the repository,
doesn't find it, and completely skips enhancement (PCEnhancer line
322). It is possible to have the enhancer fault load the metadata
and continue with enhancement?
In the mean time, I'm going to hack OpenEJB to kick off generation
very early in deployment, but it would be much more elegant to wait
until the EJB is deployed to generate the classes and this happens
after JPA is initialized.
Thanks,
-dain
Re: Should UserTransaction Work?
Posted by Kevin Sutter <kw...@gmail.com>.
Don,
One clarification...
On 1/1/07, Don Brady <db...@pobox.com> wrote:
>
>
> This is under WebSphere 6.1.
>
> Are you attempting to use OpenJPA with standard WebSphere 6.1 (ala the
DeveloperWorks article that Roland and I wrote --
http://www-128.ibm.com/developerworks/websphere/techjournal/0612_barcia/0612_barcia.html),
or are you using the EJB3/JPA Feature Pack (
https://www14.software.ibm.com/iwm/web/cc/earlyprograms/websphere/was61ejb3/)?
The Feature Pack support is a much more integrated solution. The answers to
your questions may depend on the environment. Thanks!
Kevin
Re: Should UserTransaction Work?
Posted by Kevin Sutter <kw...@gmail.com>.
Don,
Glad to hear that you got this working. Since it sounds like you are using
application-managed EntityManagers, then you should have two choices to get
your PersistenceContext associated with your BMT. As you have found out,
you can start the BMT before creating the EM. This is the easiest, but it
may not always be optimal. The other alternative is to use the
EM.joinTransaction() method. You may want to try this out as an alternative
solution.
Thanks,
Kevin
On 1/7/07, Don Brady <db...@pobox.com> wrote:
>
> Michael Dick wrote:
> >
> > If you lookup the UserTransaction in your Session Bean, then your
> > approach
> > should work. I tried making the Feature Pack sample application a BMT
> > bean
> > and it seemed to work for me. I can send you the application if you'd
> > like.
> >
> > If the transaction is started prior to looking up a BMT bean, then it
> > will
> > be suspended before the bean method
> > executes. I don't know much about web services, this might not be the
> > case
> > or possible.
>
> Michael and Craig and Kevin,
>
> I got it to work! Thanks very much for the help.
>
> My error was in failing to start the Transaction *prior to* creating
> the EntityManager. Once I did that, it worked.
>
> I should have realized that OpenJPA needed to have the Global
> Transaction already started by the time it looks to see if it is running
> in a Transaction context.
>
> As Craig mentioned, this BMT approach is a very nice pattern to have
> working, because it allows me to pass the underlying error back to the
> Web Service caller, rather than just the non-specfic
> TransactionRolledBackException from a CMT bean.
>
> Thanks,
>
> Don
>
>
>
Re: Should UserTransaction Work?
Posted by Don Brady <db...@pobox.com>.
Michael Dick wrote:
>
> If you lookup the UserTransaction in your Session Bean, then your
> approach
> should work. I tried making the Feature Pack sample application a BMT
> bean
> and it seemed to work for me. I can send you the application if you'd
> like.
>
> If the transaction is started prior to looking up a BMT bean, then it
> will
> be suspended before the bean method
> executes. I don't know much about web services, this might not be the
> case
> or possible.
Michael and Craig and Kevin,
I got it to work! Thanks very much for the help.
My error was in failing to start the Transaction *prior to* creating
the EntityManager. Once I did that, it worked.
I should have realized that OpenJPA needed to have the Global
Transaction already started by the time it looks to see if it is running
in a Transaction context.
As Craig mentioned, this BMT approach is a very nice pattern to have
working, because it allows me to pass the underlying error back to the
Web Service caller, rather than just the non-specfic
TransactionRolledBackException from a CMT bean.
Thanks,
Don
Re: Should UserTransaction Work?
Posted by Michael Dick <mi...@gmail.com>.
Hi Don,
On 1/1/07, Craig L Russell <Cr...@sun.com> wrote:
>
> Hi Don,
>
> The short answer is yes, UserTransaction is supposed to work.
>
> On Jan 1, 2007, at 11:52 AM, Don Brady wrote:
>
> > I cannot get UserTransaction to work.
> >
> > Nothing happens when I commit.
>
> Is the symptom that the commit succeeds but there is no change in the
> database?
>
> >
> > This consists of:
> >
> > - Using a JTA datasource
> > - specifying Bean Managed Transaction rather then CMT on the
> > enclosing session Bean.
> > - looking up a UserTransaction with:
> > UserTransaction userTran = (UserTransaction) initCtx
> > .lookup("java:comp/UserTransaction");
> >
> > then doing a begin on it, some entity lookup and changes, and a
> > commit.
>
> Is the EntityManagerFactory (PersistenceUnit) also declared as JTA,
> in addition to the DataSource that it uses? Both need to be JTA-enabled.
>
> >
> > Could anyone tell me if this should work?
> > This is under WebSphere 6.1.
> >
> > As background, I am able to get a JTA data source to work fine if I
> > use Container Managed Transactions rather than BMT. The problem
> > with that approach for me is that I am calling the session Bean as
> > a web-service-enable endpoint. If I leave committing the
> > transaction entirely to JTA, the commit is done after all of my
> > web service code has exited and any errors are thrown as soap
> > faults. I want to be able to catch the error and analyze it
> > before returning from the web service. I can also do this fine
> > with Resource Local Transactions but then I do not get the benefits
> > of a JTA datasource managed by WebSphere.
>
> And the possibility of using other transactional resources as well.
If you lookup the UserTransaction in your Session Bean, then your approach
should work. I tried making the Feature Pack sample application a BMT bean
and it seemed to work for me. I can send you the application if you'd like.
If the transaction is started prior to looking up a BMT bean, then it will
be suspended before the bean method
executes. I don't know much about web services, this might not be the case
or possible.
> >
> > So I am trying to use JTA with BMT which I believe would allow me
> > to catch errors on commit.
>
> Right, this is a good pattern to use in order to wrap database errors
> with your own (presumably more user-friendly) exceptions.
>
> Craig
> >
> > If this is too much of a user question for this list, please let
> > me know.....
> >
> > Thanks!
> >
> > Don
> >
> >
> >
> >
> >
> >
> >
> >
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
>
>
>
Hope this helps,
--
-Michael Dick
Re: Should UserTransaction Work?
Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Don,
The short answer is yes, UserTransaction is supposed to work.
On Jan 1, 2007, at 11:52 AM, Don Brady wrote:
> I cannot get UserTransaction to work.
>
> Nothing happens when I commit.
Is the symptom that the commit succeeds but there is no change in the
database?
>
> This consists of:
>
> - Using a JTA datasource
> - specifying Bean Managed Transaction rather then CMT on the
> enclosing session Bean.
> - looking up a UserTransaction with:
> UserTransaction userTran = (UserTransaction) initCtx
> .lookup("java:comp/UserTransaction");
>
> then doing a begin on it, some entity lookup and changes, and a
> commit.
Is the EntityManagerFactory (PersistenceUnit) also declared as JTA,
in addition to the DataSource that it uses? Both need to be JTA-enabled.
>
> Could anyone tell me if this should work?
> This is under WebSphere 6.1.
>
> As background, I am able to get a JTA data source to work fine if I
> use Container Managed Transactions rather than BMT. The problem
> with that approach for me is that I am calling the session Bean as
> a web-service-enable endpoint. If I leave committing the
> transaction entirely to JTA, the commit is done after all of my
> web service code has exited and any errors are thrown as soap
> faults. I want to be able to catch the error and analyze it
> before returning from the web service. I can also do this fine
> with Resource Local Transactions but then I do not get the benefits
> of a JTA datasource managed by WebSphere.
And the possibility of using other transactional resources as well.
>
> So I am trying to use JTA with BMT which I believe would allow me
> to catch errors on commit.
Right, this is a good pattern to use in order to wrap database errors
with your own (presumably more user-friendly) exceptions.
Craig
>
> If this is too much of a user question for this list, please let
> me know.....
>
> Thanks!
>
> Don
>
>
>
>
>
>
>
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!
Should UserTransaction Work?
Posted by Don Brady <db...@pobox.com>.
I cannot get UserTransaction to work.
Nothing happens when I commit.
This consists of:
- Using a JTA datasource
- specifying Bean Managed Transaction rather then CMT on the enclosing
session Bean.
- looking up a UserTransaction with:
UserTransaction userTran = (UserTransaction) initCtx
.lookup("java:comp/UserTransaction");
then doing a begin on it, some entity lookup and changes, and a commit.
Could anyone tell me if this should work?
This is under WebSphere 6.1.
As background, I am able to get a JTA data source to work fine if I use
Container Managed Transactions rather than BMT. The problem with that
approach for me is that I am calling the session Bean as a
web-service-enable endpoint. If I leave committing the transaction
entirely to JTA, the commit is done after all of my web service code
has exited and any errors are thrown as soap faults. I want to be able
to catch the error and analyze it before returning from the web
service. I can also do this fine with Resource Local Transactions but
then I do not get the benefits of a JTA datasource managed by WebSphere.
So I am trying to use JTA with BMT which I believe would allow me to
catch errors on commit.
If this is too much of a user question for this list, please let me
know.....
Thanks!
Don
Re: Generation of entity classes
Posted by Dain Sundstrom <da...@iq80.com>.
I think it only works if you preehnahce. The runtime enhancer will
only modify on classes with metadata loaded, and the metadata seems
to only be cached at startup.
-dain
On Jan 1, 2007, at 2:36 AM, Patrick Linskey wrote:
> Generally-speaking, you should be able to bootstrap new classes into
> OpenJPA over time. There are some situations that will prevent this
> (i.e., if exclude-unlisted-classes is set to true, and possibly some
> automatic class-scanning modes).
>
> -Patrick
>
> --
> Patrick Linskey
> BEA Systems, Inc.
>
> ______________________________________________________________________
> _
> Notice: This email message, together with any attachments, may
> contain
> information of BEA Systems, Inc., its subsidiaries and
> affiliated
> entities, that may be confidential, proprietary, copyrighted
> and/or
> legally privileged, and is intended solely for the use of the
> individual
> or entity named in this message. If you are not the intended
> recipient,
> and have received this message in error, please immediately return
> this
> by email and then delete it.
>
>> -----Original Message-----
>> From: Dain Sundstrom [mailto:dain@iq80.com]
>> Sent: Sunday, December 31, 2006 9:19 PM
>> To: open-jpa-dev@incubator.apache.org
>> Subject: Re: Generation of entity classes
>>
>> Actually, never mind. Due to the interconnectedness of persistent
>> classes (i.e., relationships), I need to generate all the classes at
>> once and add them all to the class loader at the same time. This
>> means my "elegant" solution is just broken :)
>>
>> -dain
>>
>> On Dec 31, 2006, at 3:12 PM, Dain Sundstrom wrote:
>>
>>> I working on an implementation of the EJB cmp specification which
>>> uses JPA under the covers to implement the persistence. I
>> have the
>>> basics working with hand written subclasses of the abstract cmp2
>>> beans. I just wrote a code generator to replace my hand coded
>>> subclasses using ASM (which rocks), and I am having problems
>>> getting OpenJPA to enhance my generated class. It appears that at
>>> the moment I construct the EMF all entity classes must be
>> available
>>> via the temp class loader. If they are not, OpenJPA will not add
>>> an entry into the MetaData repository. Later when I generate my
>>> class and load it, the OpenJPA transformer looks for the MetaData
>>> in the repository, doesn't find it, and completely skips
>>> enhancement (PCEnhancer line 322). It is possible to have the
>>> enhancer fault load the metadata and continue with enhancement?
>>>
>>> In the mean time, I'm going to hack OpenEJB to kick off generation
>>> very early in deployment, but it would be much more elegant
>> to wait
>>> until the EJB is deployed to generate the classes and this happens
>>> after JPA is initialized.
>>>
>>> Thanks,
>>>
>>> -dain
>>
>>
RE: Generation of entity classes
Posted by Patrick Linskey <pl...@bea.com>.
Generally-speaking, you should be able to bootstrap new classes into
OpenJPA over time. There are some situations that will prevent this
(i.e., if exclude-unlisted-classes is set to true, and possibly some
automatic class-scanning modes).
-Patrick
--
Patrick Linskey
BEA Systems, Inc.
_______________________________________________________________________
Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.
> -----Original Message-----
> From: Dain Sundstrom [mailto:dain@iq80.com]
> Sent: Sunday, December 31, 2006 9:19 PM
> To: open-jpa-dev@incubator.apache.org
> Subject: Re: Generation of entity classes
>
> Actually, never mind. Due to the interconnectedness of persistent
> classes (i.e., relationships), I need to generate all the classes at
> once and add them all to the class loader at the same time. This
> means my "elegant" solution is just broken :)
>
> -dain
>
> On Dec 31, 2006, at 3:12 PM, Dain Sundstrom wrote:
>
> > I working on an implementation of the EJB cmp specification which
> > uses JPA under the covers to implement the persistence. I
> have the
> > basics working with hand written subclasses of the abstract cmp2
> > beans. I just wrote a code generator to replace my hand coded
> > subclasses using ASM (which rocks), and I am having problems
> > getting OpenJPA to enhance my generated class. It appears that at
> > the moment I construct the EMF all entity classes must be
> available
> > via the temp class loader. If they are not, OpenJPA will not add
> > an entry into the MetaData repository. Later when I generate my
> > class and load it, the OpenJPA transformer looks for the MetaData
> > in the repository, doesn't find it, and completely skips
> > enhancement (PCEnhancer line 322). It is possible to have the
> > enhancer fault load the metadata and continue with enhancement?
> >
> > In the mean time, I'm going to hack OpenEJB to kick off generation
> > very early in deployment, but it would be much more elegant
> to wait
> > until the EJB is deployed to generate the classes and this happens
> > after JPA is initialized.
> >
> > Thanks,
> >
> > -dain
>
>
Re: Generation of entity classes
Posted by Dain Sundstrom <da...@iq80.com>.
Actually, never mind. Due to the interconnectedness of persistent
classes (i.e., relationships), I need to generate all the classes at
once and add them all to the class loader at the same time. This
means my "elegant" solution is just broken :)
-dain
On Dec 31, 2006, at 3:12 PM, Dain Sundstrom wrote:
> I working on an implementation of the EJB cmp specification which
> uses JPA under the covers to implement the persistence. I have the
> basics working with hand written subclasses of the abstract cmp2
> beans. I just wrote a code generator to replace my hand coded
> subclasses using ASM (which rocks), and I am having problems
> getting OpenJPA to enhance my generated class. It appears that at
> the moment I construct the EMF all entity classes must be available
> via the temp class loader. If they are not, OpenJPA will not add
> an entry into the MetaData repository. Later when I generate my
> class and load it, the OpenJPA transformer looks for the MetaData
> in the repository, doesn't find it, and completely skips
> enhancement (PCEnhancer line 322). It is possible to have the
> enhancer fault load the metadata and continue with enhancement?
>
> In the mean time, I'm going to hack OpenEJB to kick off generation
> very early in deployment, but it would be much more elegant to wait
> until the EJB is deployed to generate the classes and this happens
> after JPA is initialized.
>
> Thanks,
>
> -dain