CHAPTER 3 Domain models and metadata topic we ll discuss in chapter 13, section 13.1, Defining the global fetch plan. (This default-lazy=”true” switch has an interesting side effect: It switches to Hibernate 2.x default fetching behavior useful if you migrate to Hibernate 3.x but don t want to update all fetching settings.) With default-access, you enable direct field access by Hibernate for all persistent properties of all classes mapped in this file. Finally, the auto-import setting is turned off for all classes in this file. We ll talk about importing and naming of entities in chapter 4, section 4.3, Class mapping options. TIP Mapping files with no class declarations Global metadata is required and present in any sophisticated application. For example, you may easily import a dozen interfaces, or externalize a hundred query strings. In large-scale applications, you often create mapping files without actual class mappings, and only imports, external queries, or global filter and type definitions. If you look at the DTD, you can see that mappings are optional inside the root element. Split up and organize your global metadata into separate files, such as AuctionTypes.hbm.xml, AuctionQueries.hbm.xml, and so on, and load them in Hibernate s configuration just like regular mapping files. However, make sure that all custom types and filters are loaded before any other mapping metadata that applies these types and filters to class mappings. Let s look at global metadata with JDK 5.0 annotations. Global annotation metadata Annotations are by nature woven into the Java source code for a particular class. Although it s possible to place global annotations in the source file of a class (at the top), we d rather keep global metadata in a separate file. This is called package metadata, and it s enabled with a file named package-info.java in a particular package directory: @org.hibernate.annotations.TypeDefs({ @org.hibernate.annotations.TypeDef( name=”monetary_amount_usd”, typeClass = MonetaryAmountType.class, parameters = { @Parameter(name=”convertTo”, value=”USD”) } ), @org.hibernate.annotations.TypeDef( name=”monetary_amount_eur”, typeClass = MonetaryAmountType.class, parameters = { @Parameter(name=”convertTo”, value=”EUR”) } ) })
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.
This entry was posted
on Thursday, November 22nd, 2007 at 3:05 am and is filed under PHP5.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.