There are lots of Q&A’s about the size of a Java object, which is quite straightforward to understand. But I’m wondering about the size of a Java class in the PermGen space.
The reason I wonder about this is because I’m writing a code generator, generating a lot of classes. Essentially, I’m generating two classes for every table/view in a database. Now I also want to model foreign key relationships. Instead of maintaining a complex, serialisable object-structure (think about a table having a unique key being referenced by several foreign keys belonging to other tables having other foreign keys, etc), I’d prefer to generate one class per UNIQUE KEY and one class per FOREIGN KEY.
Here are my questions:
- How much overhead on the classloader and the PermGen space will I create with this?
- Is there a difference between
publicclasses,staticclasses andprivatemember classes? - Do you see a better way to generate foreign key information in source code?
I found a different solution, not wasting as much memory as generating one class per
KEY. I generate a single class that roughly looks like this:The actual tables from the generated table classes can then reference and use the above keys. I looked into JPA annotations as suggested by BobG in one of his comments. But I didn’t find them very useful to describe:
@IdClassneeds a type as parameter, and I want to avoid that type)Some of the comments mentioned why I should create such a generator, because there are lots of established frameworks. I’m doing this for http://www.jooq.org. And I feel jOOQ is filling a gap in today’s database abstraction possibilities.