Dynamicly generate class from foreign key lookup table, referencevalues
I'm generally new to Java and have a project where I've got a db
schema with normalized reference tables with static/readonly lookup
values.. I've also generated a Bean mapping from the overall schema
and was wondering how to tag(?) or annotate the reference types
(corresponding to the normalized reference/lookup tables) with their
readonly content, for example:
And in the mapped bean class
where these object.property resolves to the "Value" and
What I'd like to avoid is hard-coding the keys into the project but to
be able to reference them as a class; and without having to hard-code
the class... a data access layer might provide inserts, updates, etc.
to the FK reference values which would then reflect in the generated
Not even sure what to call what I'm talking about.
Thanks for any help.
Re: Dynamicly generate class from foreign key lookup table, reference values
Adam <email@example.com> writes:
>Not even sure what to call what I'm talking about.
You can write and load a class file at run-time.
In this case, you should adhere to the Java Class file format:
However, it usually is recommended to use code (classes) for
everything static (things that never change at run time,
that never change during the lifetime of the software).
What changes at run time is considered to be data.
Data is handled by the dynamic means intended for it,
for example container objects and so.
So your program would read the scheam from the DB and then
build everything it needs at run time from the schema as data,
not as classes. When the schema changes, it re-reads it and
re-builds what needs to be rebuilt.
For example, when you want to convert from Celsius to
Fahrenheit, and the user has input the value »32«, you store
this in a variable and then use it. You do not generate a
class with this value, then load the class and use it.
Re: Dynamicly generate class from foreign key lookup table, referencevalues
Sounds like a great candidate for Hibernate. If you're new to Java,
you can check out their site at http://www.hibernate.org/. I'm not
sure how complicated your project is, but hibernate will do exactly
what I think you are looking to do...Load DB values into POJOs, and
The basic concept is that you map out your DB to Java objects in an
XML document and Hibernate takes care of a lot of the details for you.
Hope I helped.
|All times are GMT. The time now is 09:27 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.