![]() |
Dynamicly generate class from foreign key lookup table, referencevalues
Hello,
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: table: FK_Ref_Table1 "SomeKey", "Value" "SomeOtherKey", "someOtherValue" .... And in the mapped bean class FK_Ref_TableObject.SomeKey FK_Ref_TableObject.SomeOtherKey .... where these object.property resolves to the "Value" and "someOtherValue" ... 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 class, automatically. 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 <meyer.adam@gmail.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: http://java.sun.com/docs/books/jvms/...sFile.doc.html 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 vice versa? 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. -- Michael http://javaconfessions.blogspot.com |
| All times are GMT. The time now is 10:27 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.