Hibernate (framework): Difference between revisions

Content deleted Content added
Persistence: Add link to JavaDoc and code formatting
Line 44:
 
==Persistence==
Hibernate provides transparent persistence for [[Plain Old Java Object]]s (POJOs).{{sfn|Bauer|King|Gregory|2016}}{{rp|§=3.2.2|pp=37-38}} The only strict requirement for a persistent class is a [[Nullary constructor|no-argument constructor]],{{sfn|Bauer|King|Gregory|2016}}{{rp|§=3.2.3|pp=39}} though not necessarily '''{{code|public}}'''. Proper behavior in some applications also requires special attention to the {{codeJavadoc|module=java.base|package=java.lang|class=Object|member=equals(java.lang.Object)|text=equals(Object obj)|monotype=y}} and {{codeJavadoc|module=java.base|package=java.lang|class=Object|member=hashCode()|text=hashCode()|monotype=y}} methods in the object<code>Object</code> classes.<ref>{{cite web|title=Equals and HashCode|url=https://community.jboss.org/wiki/EqualsAndHashCode|publisher=JBoss Community}}</ref> Hibernate recommends providing an identifier attribute, and this is planned to be a mandatory requirement in a future release.<ref>{{cite web|title=Hibernate User Guide: 2.5.5. Provide identifier attribute|url=http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#entity-pojo-identifier|publisher=JBoss Community}}</ref>
 
Collections of data objects are typically stored in Java collection classes, such as implementations of the {{codeJavadoc|module=java.base|package=java.util|class=Set|text=Set|monotype=y}} and {{codeJavadoc|module=java.base|package=java.util|class=List|text=List|monotype=y}} interfaces. [[Generics in Java|Java generics]], introduced in Java 5, are also supported. Hibernate can be configured to [[lazy load]] associated collections.{{sfn|Bauer|King|Gregory|2016}}{{rp|§=12.1|pp=289-293}} Lazy loading is the default as of Hibernate 3.
 
Related objects can be configured to ''[[Propagation constraint|cascade]]'' operations from one object to the other. For example, a parent {{code|Album}} class object can be configured to cascade its {{code|save}} and {{code|delete}} operations to its child {{code|Track}} class objects.