Notion of automatic dirty checking. Flushing is the process of synchronizing the memory state with the database. Updating makes a detached object persistent again (binds it to a new unit of work): so the actual database data will be updated.
Bi-directional links: it's important to set the link on both sides. All bi-directional associations need one side as inverse.
Sets: a defensive programming method is to set the getter/setter as protected, and add addToAnimals and removeFromAnimals methods.
Use one Hibernate session per request.
setFlushMode(FlushMode.MANUAL) is for read-only transactions. Test if it actually speeds things up.Ref
crit.createAlias(“parent”, “parent”, CriteriaSpecification.LEFT_JOIN); Create an alias without excluding those with parent==null
Star.java
private Set<String> planets = new HashSet<String>();
Star.hbm.xml
<set name="planets" table="star_planet"> <key column="star_id" /> <element type="text"/> </set>
Star.java
private SortedSet<String> planets = new TreeSet<String>();
Star.hbm.xml
<set name="planets" table="star_planet" sort="natural"> <key column="star_id" /> <element type="text"/> </set>
Star.java
private List<String> planets = new LinkedList<String>();
Star.hbm.xml
<list name="planets" table="star_planet"> <key column="star_id" /> <list-index column="index" /> <element type="text"/> </list>
Star.java
private Map<String, String> planets = new HashMap<String, String>();
Star.hbm.xml
<map name="planets" table="star_planet"> <key column="star_id" /> <map-key type="text" column="planet_name" /> <element type="text" column="planet_description"/> </map>
Star.java
private List<Planet> planets = new LinkedList<Planet>();
Star.hbm.xml
<list name="planets" table="star_planet"> <key column="star_id" /> <list-index column="index" /> <many-to-many column="planet_id" class="Planet"/> </list>