Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think entity relations make your coding easier, generally speaking, especially when querying for objects: what's easier than saying person.getOption().getDescription()? This approach does have drawbacks, however:</p> <ul> <li>Referenced entities have to be loaded from the DB, especially when you have save-cascade. In save-cascade, as you probably know, Hibernate will complain the object exists in the DB. I'm not sure what happens when you don't have save-cascade.</li> <li>Referenced entities have to be loaded with either a separate query, or an outer join on the loading of the main entity. <em>Can</em> cause performance problems.</li> </ul> <p>Persisting the keys as mere properties can help in cases of complex relationships, for example when referencing a <em>big</em> entity with much loading to be done by Hibernate. This approach can help make loading the "master" entity lighter for the system. It does mean that <em>you</em> will have to do the entity loading yourself, if you need its properties. I'd say that for immutable "look-up" type entities, you could safely keep an in-memory Map of their instances and get() them by their key, instead of going to the DB. The down-side is that you will partition your entity-handling logic: you will have to remember which entities to cache and manage their caches.</p> <p>I'd say that, in general, it's always better to work with entities, which is your model after all. Hibernate insists in noting that it helps you persist your object model to help you. It is only logical to delegate as much of the persistence stuff to Hibernate then. There <em>are</em> cases however, that Hibernate can't cope very well with a "proper" model: entities with many relations, "hot" entities that get used all the time, etc. In these cases, if Hibernate's mechanisms can't help (2nd level cache for example) you really have to resort to such "tricks" and do some of the work yourself.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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