You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by su...@accenture.com on 2007/05/14 11:14:48 UTC
Need help
Hi JPA Team,
I am trying to learn JPA and thanks for your efforts to develop the JPA.
I am trying to execute the sample program given in 5 minute quick start
guide to OpenJPA <http://incubator.apache.org/openjpa/quick-start.html>
. I am able to execute and see the result in console. But how to connect
to Derby database which is comes along with the package. In
persistence.xml I found that you open the connection. But how to connect
derby database and see the data in the table Message (since we are
creating & inserting into the Message table).
Thanks,
Regards
Sanku Subrahmanyam
Accenture - Bangalore
Ph : 080 4106 2113
Mob: 9886623009
This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited.
Re: Entity creation at Runtime
Posted by Patrick Linskey <pl...@gmail.com>.
Also, depending on how you have things configured, OpenJPA can lazily
discover classes for a given EntityManager. So, you shouldn't
necessarily need to re-initialize / reload anything in particular.
-Patrick
On 5/14/07, Marc Prud'hommeaux <mp...@apache.org> wrote:
> James-
>
> The CodeGenerator just generates .java file, so I don't think it will
> be useful for your purposes.
>
> Well, I suspect that if if you are currently generating classes using
> CGLIB, then the easiest thing would be to just use CGLIB to add the
> annotations as well.
>
> Alternately, you could instead generate a separate orm.xml mapping
> file conforming to the JPA specification, which would allow you to
> define the mappings separately.
>
>
>
> On May 14, 2007, at 11:18 AM, James Hang wrote:
>
> > Thanks for the reply Marc.
> >
> > Is there a third party tool that can generate classes with
> > annotations?
> > Or is there something in OpenJPA that can do that? I noticed a
> > CodeGenerator class that can generate classes from metadata. Can I
> > use
> > that?
> >
> > I'll take a look at the PCClassFileTransformer class like you
> > suggested.
> >
> > Thanks for your help!
> >
> > James
> >
> >
> >
> > -----Original Message-----
> > From: Marc Prud'hommeaux [mailto:mprudhomapache@gmail.com] On
> > Behalf Of
> > Marc Prud'hommeaux
> > Sent: Monday, May 14, 2007 10:30 AM
> > To: open-jpa-dev@incubator.apache.org
> > Subject: Re: Entity creation at Runtime
> >
> > James-
> >
> > It should be possible. The easiest way (and the most implementation-
> > agnostic) would be to simply generate the classes with the
> > appropriate mapping annotations, and then just load them at runtime.
> >
> > The somewhat tricky part would be to ensure they get enhanced by the
> > system when they are loaded. You could just run the -
> > javaagent:openjpa.jar flag with no arguments, and I believe it will
> > scan all loaded classes for annotations, but that can slow things
> > down quite a bit. A faster solution would be to run your generated
> > classes through the enhancer.
> >
> > Take a look at the code for
> > org.apache.openjpa.enhance.PCClassFileTransformer ... if you can't
> > use that directly, then it might be good to use as a starting point.
> >
> >
> >
> > On May 14, 2007, at 10:00 AM, James Hang wrote:
> >
> >> Hi,
> >>
> >> I'm curious if it's possible to create and map new entities at
> >> Runtime?
> >> We have an application which allows users to design new data
> >> models at
> >> runtime. When new tables are being created in the database, we would
> >> like to make OpenJPA aware of them. We are currently doing this in
> >> Hibernate by generating the POJO classes dynamically using CGLIB,
> >> adding
> >> dynamically generated xml mappings to the Hibernate runtime
> >> configuration and re-initializing the SessionFactory. Is there a
> >> way to
> >> do something similar in OpenJPA?
> >>
> >> Thanks,
> >>
> >> James
> >>
> >>
> >> 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.
> >
> >
> > 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.
>
>
--
Patrick Linskey
202 669 5907
Re: Entity creation at Runtime
Posted by Marc Prud'hommeaux <mp...@apache.org>.
James-
The CodeGenerator just generates .java file, so I don't think it will
be useful for your purposes.
Well, I suspect that if if you are currently generating classes using
CGLIB, then the easiest thing would be to just use CGLIB to add the
annotations as well.
Alternately, you could instead generate a separate orm.xml mapping
file conforming to the JPA specification, which would allow you to
define the mappings separately.
On May 14, 2007, at 11:18 AM, James Hang wrote:
> Thanks for the reply Marc.
>
> Is there a third party tool that can generate classes with
> annotations?
> Or is there something in OpenJPA that can do that? I noticed a
> CodeGenerator class that can generate classes from metadata. Can I
> use
> that?
>
> I'll take a look at the PCClassFileTransformer class like you
> suggested.
>
> Thanks for your help!
>
> James
>
>
>
> -----Original Message-----
> From: Marc Prud'hommeaux [mailto:mprudhomapache@gmail.com] On
> Behalf Of
> Marc Prud'hommeaux
> Sent: Monday, May 14, 2007 10:30 AM
> To: open-jpa-dev@incubator.apache.org
> Subject: Re: Entity creation at Runtime
>
> James-
>
> It should be possible. The easiest way (and the most implementation-
> agnostic) would be to simply generate the classes with the
> appropriate mapping annotations, and then just load them at runtime.
>
> The somewhat tricky part would be to ensure they get enhanced by the
> system when they are loaded. You could just run the -
> javaagent:openjpa.jar flag with no arguments, and I believe it will
> scan all loaded classes for annotations, but that can slow things
> down quite a bit. A faster solution would be to run your generated
> classes through the enhancer.
>
> Take a look at the code for
> org.apache.openjpa.enhance.PCClassFileTransformer ... if you can't
> use that directly, then it might be good to use as a starting point.
>
>
>
> On May 14, 2007, at 10:00 AM, James Hang wrote:
>
>> Hi,
>>
>> I'm curious if it's possible to create and map new entities at
>> Runtime?
>> We have an application which allows users to design new data
>> models at
>> runtime. When new tables are being created in the database, we would
>> like to make OpenJPA aware of them. We are currently doing this in
>> Hibernate by generating the POJO classes dynamically using CGLIB,
>> adding
>> dynamically generated xml mappings to the Hibernate runtime
>> configuration and re-initializing the SessionFactory. Is there a
>> way to
>> do something similar in OpenJPA?
>>
>> Thanks,
>>
>> James
>>
>>
>> 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.
>
>
> 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.
RE: Entity creation at Runtime
Posted by Pinaki Poddar <pp...@bea.com>.
You can use Serp -- a bytecode manipulation library --
(http://serp.sourceforge.net/). OpenJPA itself uses it to enhance class
files.
To enhance the dynamically defined class and register it to OpenJPA
persistence unit requires few considerations. The attached example
demonstrates these steps with a simple example that
a) defines a class dynamically
b) enhances
c) defines database mapping for it
d) pouplates instance of the defined class
and finally persists it.
Pinaki Poddar
BEA Systems
415.402.7317
-----Original Message-----
From: James Hang [mailto:jhang@bea.com]
Sent: Monday, May 14, 2007 1:18 PM
To: open-jpa-dev@incubator.apache.org
Subject: RE: Entity creation at Runtime
Thanks for the reply Marc.
Is there a third party tool that can generate classes with annotations?
Or is there something in OpenJPA that can do that? I noticed a
CodeGenerator class that can generate classes from metadata. Can I use
that?
I'll take a look at the PCClassFileTransformer class like you suggested.
Thanks for your help!
James
-----Original Message-----
From: Marc Prud'hommeaux [mailto:mprudhomapache@gmail.com] On Behalf Of
Marc Prud'hommeaux
Sent: Monday, May 14, 2007 10:30 AM
To: open-jpa-dev@incubator.apache.org
Subject: Re: Entity creation at Runtime
James-
It should be possible. The easiest way (and the most implementation-
agnostic) would be to simply generate the classes with the appropriate
mapping annotations, and then just load them at runtime.
The somewhat tricky part would be to ensure they get enhanced by the
system when they are loaded. You could just run the -
javaagent:openjpa.jar flag with no arguments, and I believe it will scan
all loaded classes for annotations, but that can slow things down quite
a bit. A faster solution would be to run your generated classes through
the enhancer.
Take a look at the code for
org.apache.openjpa.enhance.PCClassFileTransformer ... if you can't use
that directly, then it might be good to use as a starting point.
On May 14, 2007, at 10:00 AM, James Hang wrote:
> Hi,
>
> I'm curious if it's possible to create and map new entities at
> Runtime?
> We have an application which allows users to design new data models at
> runtime. When new tables are being created in the database, we would
> like to make OpenJPA aware of them. We are currently doing this in
> Hibernate by generating the POJO classes dynamically using CGLIB,
> adding dynamically generated xml mappings to the Hibernate runtime
> configuration and re-initializing the SessionFactory. Is there a way
> to do something similar in OpenJPA?
>
> Thanks,
>
> James
>
>
> 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.
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.
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.
RE: Entity creation at Runtime
Posted by James Hang <jh...@bea.com>.
Thanks for the reply Marc.
Is there a third party tool that can generate classes with annotations?
Or is there something in OpenJPA that can do that? I noticed a
CodeGenerator class that can generate classes from metadata. Can I use
that?
I'll take a look at the PCClassFileTransformer class like you suggested.
Thanks for your help!
James
-----Original Message-----
From: Marc Prud'hommeaux [mailto:mprudhomapache@gmail.com] On Behalf Of
Marc Prud'hommeaux
Sent: Monday, May 14, 2007 10:30 AM
To: open-jpa-dev@incubator.apache.org
Subject: Re: Entity creation at Runtime
James-
It should be possible. The easiest way (and the most implementation-
agnostic) would be to simply generate the classes with the
appropriate mapping annotations, and then just load them at runtime.
The somewhat tricky part would be to ensure they get enhanced by the
system when they are loaded. You could just run the -
javaagent:openjpa.jar flag with no arguments, and I believe it will
scan all loaded classes for annotations, but that can slow things
down quite a bit. A faster solution would be to run your generated
classes through the enhancer.
Take a look at the code for
org.apache.openjpa.enhance.PCClassFileTransformer ... if you can't
use that directly, then it might be good to use as a starting point.
On May 14, 2007, at 10:00 AM, James Hang wrote:
> Hi,
>
> I'm curious if it's possible to create and map new entities at
> Runtime?
> We have an application which allows users to design new data models at
> runtime. When new tables are being created in the database, we would
> like to make OpenJPA aware of them. We are currently doing this in
> Hibernate by generating the POJO classes dynamically using CGLIB,
> adding
> dynamically generated xml mappings to the Hibernate runtime
> configuration and re-initializing the SessionFactory. Is there a
> way to
> do something similar in OpenJPA?
>
> Thanks,
>
> James
>
>
> 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.
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.
Re: Entity creation at Runtime
Posted by Marc Prud'hommeaux <mp...@apache.org>.
James-
It should be possible. The easiest way (and the most implementation-
agnostic) would be to simply generate the classes with the
appropriate mapping annotations, and then just load them at runtime.
The somewhat tricky part would be to ensure they get enhanced by the
system when they are loaded. You could just run the -
javaagent:openjpa.jar flag with no arguments, and I believe it will
scan all loaded classes for annotations, but that can slow things
down quite a bit. A faster solution would be to run your generated
classes through the enhancer.
Take a look at the code for
org.apache.openjpa.enhance.PCClassFileTransformer ... if you can't
use that directly, then it might be good to use as a starting point.
On May 14, 2007, at 10:00 AM, James Hang wrote:
> Hi,
>
> I'm curious if it's possible to create and map new entities at
> Runtime?
> We have an application which allows users to design new data models at
> runtime. When new tables are being created in the database, we would
> like to make OpenJPA aware of them. We are currently doing this in
> Hibernate by generating the POJO classes dynamically using CGLIB,
> adding
> dynamically generated xml mappings to the Hibernate runtime
> configuration and re-initializing the SessionFactory. Is there a
> way to
> do something similar in OpenJPA?
>
> Thanks,
>
> James
>
>
> 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.
Entity creation at Runtime
Posted by James Hang <jh...@bea.com>.
Hi,
I'm curious if it's possible to create and map new entities at Runtime?
We have an application which allows users to design new data models at
runtime. When new tables are being created in the database, we would
like to make OpenJPA aware of them. We are currently doing this in
Hibernate by generating the POJO classes dynamically using CGLIB, adding
dynamically generated xml mappings to the Hibernate runtime
configuration and re-initializing the SessionFactory. Is there a way to
do something similar in OpenJPA?
Thanks,
James
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.
Re: Need help
Posted by Marc Prud'hommeaux <mp...@apache.org>.
Sanku-
If you look in Main.java, you can see we are passing the System
properties to the EntityManager creation process:
EntityManagerFactory factory = Persistence.
createEntityManagerFactory("hellojpa",
System.getProperties());
In the parent directory's build.xml file, you can see we pass system
properties to the <java> process that declares the database driver,
URL, connection name, and password.
This step of indirection might be a bit confusing, but it does allow
you to easily swap out properties for some other database you want to
test by just specifying them on the command line. E.g., something like:
ant -Ddbdriver=com.somecompany.Driver -Ddburl=jdbc:somedburl -
Dbuser=myuser -Ddbpass=somepass
Of course, you can always just un-comment the <properties> section of
the persistence.xml and not bother passing the system properties to
the creation process as well.
On May 14, 2007, at 2:14 AM, <su...@accenture.com> wrote:
> Hi JPA Team,
>
>
>
> I am trying to learn JPA and thanks for your efforts to develop the
> JPA.
>
>
>
>
> I am trying to execute the sample program given in 5 minute quick
> start
> guide to OpenJPA <http://incubator.apache.org/openjpa/quick-
> start.html>
> . I am able to execute and see the result in console. But how to
> connect
> to Derby database which is comes along with the package. In
> persistence.xml I found that you open the connection. But how to
> connect
> derby database and see the data in the table Message (since we are
> creating & inserting into the Message table).
>
>
>
>
>
> Thanks,
>
>
>
> Regards
>
> Sanku Subrahmanyam
>
> Accenture - Bangalore
>
> Ph : 080 4106 2113
>
> Mob: 9886623009
>
>
>
>
>
> This message is for the designated recipient only and may contain
> privileged, proprietary, or otherwise private information. If you
> have received it in error, please notify the sender immediately and
> delete the original. Any other use of the email by you is prohibited.