openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <...@cndavies.com>
Subject RE: Dynamic entity definition creation - is it possible?
Date Thu, 23 Jul 2009 17:12:23 GMT
Hmm thanks Donald I'll take a look at these projects..so much I don't know
:)


-----Original Message-----
From: Donald Woods [mailto:dwoods@apache.org] 
Sent: Friday, 24 July 2009 2:31 AM
To: users@openjpa.apache.org
Subject: Re: Dynamic entity definition creation - is it possible?

Just taking a stab at this, as I've never tried it....

1) Use DdlUtils to dump the existing DB schema to XML, update the schema 
with the new columns and then alter the DB -
    http://db.apache.org/ddlutils/
2) Use Torque to generate Java classes from the schema XML -
    http://db.apache.org/torque/index.html
3) Use the new JPA2 Metamodel and Criteria API features in OpenJPA trunk
    - use the metamodel generator in scripts/mmg.bat to create the 
*_.java classes
    - use the criteria api and metamodel updated classes for your 
persistence code

I may be mistaken about #3, but Pinaki can correct me and provide more 
details on if those new JPA2 features apply here.


-Donald



C N Davies wrote:
> I might be thinking in the wrong direction so feel free to berate me if I
> am.
> 
>  
> 
> My app imports data from various sources including excel (uses Apache
POI),
> CSV, SQL result set etc. Prior to starting to use OpenJPA, if my import
> processes noted any changes to the incoming data set (ie additional
fields)
> I would dynamically generate SQL to  modify the data tables to accommodate
> any changes to the incoming data set. (ie a vendor adds a new column to a
> spreadsheet I imports regularly so I add the required columns) and then
> commit the new data so that any changes to the structure of the incoming
> data can be dynamically managed at runtime.
> 
>  
> 
> Since JPA requires class files to define the structure of an entity, if I
> have an entity class that expects certain fields, but I receive an
> additional column in my incoming dataset, then my entity will just miss
the
> new data.
> 
>  
> 
> I was thinking that maybe there is a solution that would function at
runtime
> like this:
> 
>  
> 
> 1.       Examine the incoming data from a CSV file for example (easy to do
> and already done)
> 
> 2.       Create the appropriate entity definition at runtime (possible
???)
> 
> 3.       Create an instance of this new definition  (assuming 2 can be
done
> this should be as per usual)
> 
> 4.       Populate the new instance (assuming 2 can be done this should be
as
> per usual)
> 
> 5.       Call OpenJPA persist/merge (What about JPA enhancement of the
> modified/generated entity classes?)
> 
>  
> 
> I do understand the implications of doing this kind of dynamic
restructuring
> in a production system, however I'm painting a generic picture of my
thought
> process here in order to convey a concept rather than babble on about the
> specifics of the system.
> 
>  
> 
> Have I lost the plot or can this be done using OpenJPA?  I've read the
whole
> doc a dozen times, search the mail lists but can't see any way to do it. 
> 
>  
> 
> Thanks!
> 
>  
> 
> Chris
> 
>  
> 
> 


Mime
View raw message