Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate Lookup tables: As an Object Relation or as a code/key
    primarykey
    data
    text
    <p>So, I'm working on an application with lots of relations and lookup tables, but It all boils down to this:</p> <p><strong>Person</strong></p> <pre><code>id INT (PK) ... (name, address, etc) optcode VARCHAR (FK to Options) typecode VARCHAR (FK to Types) </code></pre> <p><strong>Options</strong></p> <pre><code>optcode VARCHAR (PK) optdesc VARCHAR ... (more meta data, like date added, etc) </code></pre> <p><strong>Types</strong></p> <pre><code>code VARCHAR (PK) desc VARCHAR ... (more meta data, like date added, etc) </code></pre> <p>I'm using hibernate to access these tables and on the one hand, Object Relations have benefits, but on the other hand, just using Strings for the codes works better.</p> <p>What is better Object Relations vs Keys vs both?</p> <p>Just using Keys:</p> <pre><code>public class Person { private int id; ... (more attributes) private String optcode; private String typecode; } In the services: Person person = new Person(); person.setOptcode("ABC"); person.setTypecode("XYZ"); session.save(person); </code></pre> <p>Or the O/R way:</p> <pre><code>public class Person { private int id; ... (more attributes) @JoinColumn private Options option; @JoinColumn private Types type; } In the services: Person person = new Person(); person.setOption(new Options("ABC")); //Assume constructor fills in the 'optcode' person.setType(new Types("XYZ")); //Same, with 'code' session.save(person); </code></pre> <p>In most cases of persistence, I only have the 'code', but many times when displaying the data it would be nice to show the 'desc'</p> <p>Since I'll have a place to manage the Options and Types entities, those will exist anyways, but it just is annoying to have to wrap the 'code' in an object.</p> <p>What do you think are the pros/cons of the different ways? What if I just put both into the Person object so i can use what ever is more convinent? What about making setters that just shove the string into a new Options/Types entity?</p> <p>I'm trying to pin down the best way so it can be consistent, right now I've just been doing whatever required the least amount of new entities, but eventually everything will be represented by hibernate entities.</p> <p><strong>Update:</strong> The Person Entity will end up having almost 20 unique entity relations (each one pointing to a different table), The web-ui will probably have drop-down lists containing the values for each table, so I expect that I'll only have the 'code' to use for persistence. <strong>Related:</strong> I'm actually using a PersonImpl (plain POJO) and a PersonEntity (Hibernate Entity) and Dozer Mapping to go between.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload