Java Reference
In-Depth Information
<property name="connection.url">
jdbc:hsqldb:file:annotationsdb;shutdown=true
</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="hibernate.connection.pool_size">0</property>
<property name="show_sql">false</property>
<property name="dialect">
org.hibernate.dialect.HSQLDialect
</property>
<!-- Mapping files -->
<mapping class="com.hibernatebook.annotations.Author"/>
<mapping class="com.hibernatebook.annotations.AuthorAddress"/>
<mapping class="com.hibernatebook.annotations.Book"/>
<mapping class="com.hibernatebook.annotations.Address"/>
<mapping class="com.hibernatebook.annotations.Publisher"/>
<mapping class="com.hibernatebook.annotations.ComputerBook"/>
</session-factory>
</hibernate-configuration>
You can also add an annotated class to your Hibernate configuration programmatically.
The annotations toolset comes with an org.hibernate.cfg.AnnotationConfiguration object
that extends the base Hibernate Configuration object for adding mappings. The methods on
AnnotationConfiguration for adding annotated classes to the configuration are as follows:
addAnnotatedClass(Class persistentClass) throws MappingException
addAnnotatedClasses(List<Class> classes)
addPackage(String packageName) throws MappingException
Using these methods, you can add one annotated class, a list of annotated classes, or an
entire package (by name) of annotated classes. As with the Hibernate XML configuration file,
the annotated entities are interoperable with XML mapped entities.
Hibernate 3-Specific Persistence Annotations
Table 6-2 lists the Hibernate-specific annotations. We will now look at some of these Hibernate-
specific annotations in more detail—however, bear in mind that using any of this functionality
potentially reduces the portability of your application to other EJB 3 solutions.
Annotations that are not recognized by an EJB 3 environment will be ignored, rather than
causing a runtime exception directly—however, this may result in different runtime applica-
tion behavior that may not be desirable. In some cases, Hibernate 3 annotations can be used
to prepare resources that are referenced by standard EJB 3 annotations, in which case the
application will fail when the EJB 3 environment attempts to use the missing resource.
Search WWH ::




Custom Search