tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Tapestry > Hibernate - Core - Conf
Date Sat, 13 Nov 2010 10:40:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/12/_/styles/combined.css?spaceKey=TAPESTRY&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/TAPESTRY/Hibernate+-+Core+-+Conf">Hibernate
- Core - Conf</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~ccordenier">Christophe
Cordenier</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Fix broken links<br />
    </div>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >For each package contributed, the
library will: <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >* [Add the package to the <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">configuration|http://www.hibernate.org/hib_docs/annotations/api/org/hibernate/cfg/AnnotationConfiguration.html#addPackage(java.lang.String)],</span>
<span class="diff-added-words"style="background-color: #dfd;">configuration|http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/cfg/AnnotationConfiguration.html#addPackage(java.lang.String)],</span>
which will load annotations from the package-info class within the named package, if present.
<br></td></tr>
            <tr><td class="diff-changed-lines" >* Every Java class in the package
(or any subpackage) will be [added as an annotated <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">class|http://www.hibernate.org/hib_docs/annotations/api/org/hibernate/cfg/AnnotationConfiguration.html#addAnnotatedClass(java.lang.Class)].</span>
<span class="diff-added-words"style="background-color: #dfd;">class|http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/cfg/AnnotationConfiguration.html#addAnnotatedClass(java.lang.Class)].</span>
This excludes inner classes, but includes all other classes. <br></td></tr>
            <tr><td class="diff-unchanged" >By default, the package _application-root-package_.entities
is scanned as described above. If you have additional packages containing entities, you must
[contribute|../tapestry-ioc/configuration.html] them to the tapestry.hibernate.HibernateEntityPackageManager
service configuration. <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="Hibernate-Core-Conf-ConfiguringHibernate"></a>Configuring
Hibernate</h1>

<p>The Tapestry Hibernate Library is responsible for configuring Hibernate for you.
This is done in a just-in-time manner, the first time a Hibernate Session is required.</p>

<h2><a name="Hibernate-Core-Conf-HibernateSessionSourceConfiguration"></a>HibernateSessionSource
Configuration</h2>

<p>One way to configure hibernate is to create a <tt>hibernate.cfg.xml</tt>
file and place it in the root of your application (i.e., under src/main/resources). Most Hibernate-specific
configuration occurs in this file. Another way is to contribute objects that perform configuration
(such as setting event listeners). Example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> <span class="code-keyword">static</span>
void contributeHibernateSessionSource(OrderedConfiguration&lt;HibernateConfigurer&gt;
config)
{
  config.add(<span class="code-quote">"Widget"</span>, <span class="code-keyword">new</span>
WidgetHibernateConfigurer());
}</pre>
</div></div>

<p>Note that the configuration is an OrderedConfiguration. The library contributes two
configurers by default:</p>

<ul>
	<li><b>Default</b> - performs default hibernate configuration</li>
	<li><b>PackageName</b> - loads entities by package name as contributed
to the HibernateEntityPackageManager service
<h2><a name="Hibernate-Core-Conf-HibernateEntityPackageManagerConfiguration"></a>HibernateEntityPackageManager
Configuration</h2></li>
</ul>


<p>This configuration is a set of package names, identifying where to search for entity
classes.</p>

<p>For each package contributed, the library will:</p>

<ul>
	<li><a href="http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/cfg/AnnotationConfiguration.html#addPackage(java.lang.String)"
class="external-link" rel="nofollow">Add the package to the configuration</a>, which
will load annotations from the package-info class within the named package, if present.</li>
	<li>Every Java class in the package (or any subpackage) will be <a href="http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/cfg/AnnotationConfiguration.html#addAnnotatedClass(java.lang.Class)"
class="external-link" rel="nofollow">added as an annotated class</a>. This excludes
inner classes, but includes all other classes.<br/>
By default, the package <em>application-root-package</em>.entities is scanned
as described above. If you have additional packages containing entities, you must <span
class="error">&#91;contribute|../tapestry-ioc/configuration.html&#93;</span>
them to the tapestry.hibernate.HibernateEntityPackageManager service configuration.</li>
</ul>


<p>Example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> <span class="code-keyword">static</span>
void contributeHibernateEntityPackageManager(Configuration&lt;<span class="code-object">String</span>&gt;
configuration)
{
  configuration.add(<span class="code-quote">"org.example.myapp.domain"</span>);
}</pre>
</div></div>

<p>You may add as many packages in this manner as you wish. This option is most often
used when the entities themselves are contained in a library included within an application,
rather than part of the application directly.</p>

<h1><a name="Hibernate-Core-Conf-HibernateSymbols"></a>Hibernate Symbols</h1>

<p>The Hibernate integration includes a number of <span class="error">&#91;symbols|../tapestry-ioc/symbols.html&#93;</span>
used to control certain features:</p>

<p> tapestry.hibernate.provide-entity-value-encodersIf true (the default) then ValueEncoders
are automatically provided for all Hibernate entities (ValueEncoders are used to encode the
primary keys of entities as strings that can be included in URLs). Set to false if you want
direct control over this feature. tapestry.hibernate.default-configurationIf true (the default),
then the application must include a <tt>hibernate.cfg.xml</tt> file. If your application
configures itself entirely in code, you should set this symbol to false. tapestry.hibernate.early-startup
If "true", the Hibernate is initialized when the application starts up. The default is "false",
to start Hibernate up lazily, on first use.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/TAPESTRY/Hibernate+-+Core+-+Conf">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=23338470&revisedVersion=2&originalVersion=1">View
Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message