294 APPENDIX B n HIBERNATE TOOLS APPENDIX B n HIBERNATE TOOLS The
element allows you to include and exclude groups of tables from the mapping process on the basis of pattern matches on their names. Where the element allows you to specify a set of tables matching a single pattern to be reverse engineered, the
element operates within this and allows multiple patterns to be applied to include and exclude tables. Here s an example:
Although the previous element included all tables within the current schema that matched the pattern NOTE*, this table filter excludes any tables that match the pattern NOTEPAD_ARCHIVE* from reverse engineering. Table filters are applied in order, so using this technique, you can build up a filter that only includes a specific set of tables. The
task permits almost total control over the mapping details of the entity. You can select a specific table by catalog, schema, and name. You can specify the class name that it should take, how the primary key column(s) relate to that class s properties, the primary key generator that it should use, the column types and properties that they are associated with, and the details of the associations formed by foreign key relationships. Our simple example places the generated entity into an appropriate class, with a nonstandard primary key property name and a nonstandard type mapping for one of the columns (note). It also excludes one of the columns (audit) from the entity model.
If it looks like you will have to manage the reverse engineering process to this level of detail, it may in fact be more appropriate to create some or all of the mapping files manually, which gives you total control over the specification of those entities. Complex specification of mapping information in the reverse engineering file is really only appropriate if it is for exceptional classes when the general cases are common; or if you expect to need to regenerate the model from the schema very frequently in response to changes in the schema details. Templates With the exception of and , all the Ant exporter tasks take the metamodel information from the configuration, pass it to a set of FreeMarker templates, and write the output to files. For more information on the FreeMarker template scripting language, see the FreeMarker site at http://freemarker.sourceforge.net.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.
Posted in tomcat | No Comments »
Wednesday, October 3rd, 2007
APPENDIX B n HIBERNATE TOOLS 293 n HIBERNATE TOOLS 293
The reverse engineering file in the preceding code limits the tables to be used when generating the mapping information from the schema to the three explicitly named tables (NOTE, NOTEPAD, and NOTEPAD_NOTE) in the database s public schema. A reverse engineering file always consists of a single top-level element containing various additional elements. These daughter elements are given in order in Table B-10: Table B-10. The Elements Used in Configuring the Reverse Engineering File Element Cardinality Description Zero or more Allows the reverse engineering process to be limited by catalog, schema, and table name Zero or one Allows you to override the default mapping between database types and Java types
Zero or more Allows you to include or exclude tables by catalog name, schema name, and table name, and allows them to be grouped into a particular package
Zero or more Allows you to override the default mappings of tables into entities Rather than trying to exhaustively specify the syntax of a reverse engineering file, which is anyway available through the DTD at http://hibernate.sourceforge.net/hibernate-reverseengineering- 3.0.dtd, we think it is easier to follow the basic requirements of the file format with some examples of valid , ,
, and
elements. Our first example specifies the following rule: tables should only be used for reverse engineering if they are in the public schema and their names begin with NOTE: Our next example enforces a rule that database INTEGERtypes for which the column is specified as NOT NULL must be represented using Hibernate s inttype. It also enforces a rule that database VARCHAR types that have a specified length of 250 should be treated as Hibernate string types. These type mappings apply throughout the reverse engineering process you cannot specify them on a per-table basis using the element, but you can using the
element.
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.
Posted in tomcat | No Comments »
Tuesday, October 2nd, 2007
292 APPENDIX B n HIBERNATE TOOLS APPENDIX B n HIBERNATE TOOLS The reversestrategy attribute allows you to specify the fully qualified class name of a custom implementation of the org.hibernate.cfg.reveng.ReverseEngineeringStrategy interface. This interface defines methods that can be used to select the following: Class names from table details Property names from column details One-to-many associations from foreign key relationships Many-to-one associations from foreign key relationships Inverse relationships from foreign key relationships Lazy loading details from foreign key relationships Collection attribute names from foreign key relationships Entity names from foreign key relationships Tables and columns to include and exclude Primary key columns from table details The column to use for optimistic locking strategies Composite ID details from table details It also allows you to provide information about how schemas should be generated from the resulting metamodel. This information is as follows: Additional foreign key relationships The table naming strategy to be used The disadvantage of this approach to managing the reverse engineering process is that it is not particularly flexible, and it requires a lot of coding. Reverse engineering is often carried out only once to establish the mappings, with the schema thereafter being driven from the mappings, rather than being used to create them. The Hibernate tools therefore provide a second mechanism for controlling the reverse engineering process by specifying an XML configuration file using the revengfileattribute of the task. This provides nearly the same degree of control, but is much simpler to create especially if you intend to manipulate only minor details of the process. The output of the reverse engineering tool described in the The Reverse Engineering and Code Generation Tools section is actually a reverse engineering XML file following this format. A very simple example reverse engineering file is shown in the following code:
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.
Posted in tomcat | No Comments »
Tuesday, October 2nd, 2007
APPENDIX B n HIBERNATE TOOLS 291 n HIBERNATE TOOLS 291 In principle, the element allows you to specify an arbitrary HQL query that will be run against the database using the configuration s mapping information. Table B-9 shows the attributes that can be supplied. Table B-9. The Properties Available to the Exporter Element Property Default Description destdir If set, overrides, for this exporter only, the destination directory specified on the tools task. destfile If set, specifies the file into which the output of the queries will be written. If left unset, the query is carried out, but the output is not saved. The HQL query itself is included as the body of the element. select n.owner from Notepad n If you want to include multiple SQL queries in the task, you can include multiple nested elements thus: select n.owner from Notepad n select n.owner from Note n Reverse Engineering As we discussed in the previous section, the task can be used to create a configuration metamodel directly from a database schema. However, a database schema is not necessarily an exact match for the entity mappings that we want to create. It may contain tables and columns that we would prefer to omit from our entities. It may also lack some of the information that we want to express. For example, database types such as VARCHAR do not map exactly to Java types such as char[]and java.lang.String, and the tables will have names that do not conform to the Java naming conventions. Used as is, the task will select sensible defaults for the type names, and will assign the reverse-engineered tables suitable Java names derived from the table names. It also provides an attribute to allow you to directly specify a suitable package name. Even so, we would really like more control over the specifics of the reverse engineering process. Note that while it also provides a naming strategy attribute, this has no effect during the reverse engineering process, as naming strategy classes can only be used to determine schema names from mapping information, not vice versa. Hibernate provides two ways in which this process can be controlled you can specify one of two attributes on the task to override the default behavior.
You want to have a cheap webhost for your apache application, then check apache web hosting services.
Posted in tomcat | No Comments »
Monday, October 1st, 2007
290 APPENDIX B n HIBERNATE TOOLS APPENDIX B n HIBERNATE TOOLS This exporter can be used to permit the mapping file based creation of suitable classes, or to create classes from the database schema when is used. The element generates the XML mapping files from the information con tained in the metamodel. Table B-6 shows the attributes that can be supplied. Table B-6. The Attributes Available to the Element Property Default Description destdir If set, overrides, for this exporter only, the destination directory specified on the tools task This exporter is particularly terse because it only writes out the mapping information stored in the metamodel. This is all handled by the appropriate configuration element. The exporter just needs to know which path to write the XML files into. And that can be specified at the Hibernate tool level. A fairly typical invocation of this exporter is, in its entirety, the ridiculously simple . The element generates HTML documentation of the schema and entities in a style similar to the familiar javadoc output. Table B-7 shows the attributes that can be supplied. Table B-7. The Attributes Available to the Exporter Element Property Default Description destdir If set, overrides, for this exporter only, the destination directory specified on the tools task The element generates a set of basic DAO classes one for each of the entities in the metadata. Table B-8 shows the attributes that can be supplied. Table B-8. The Attributes Available to the Exporter Element Property Default Description destdir If set, overrides, for this exporter only, the destination directory specified on the tools task By default, these DAO classes will be named after your entity, suffixed with Home. The generated DAOs provide a set of methods roughly corresponding to the methods available on the Session interface, but strongly tied to the entity type. While the generated DAOs can provide a useful foundation for your own more specific DAOs, we generally find that they offer little value beyond that already offered from the standard Session interactions. nNote Nothing in any of the exporters intrinsically stops you from generating silly combinations of output but this has its advantages; for example, it is possible to use an configuration element with the exporter to generate POJOs. While that might seem pointless, given that you have to start with POJOs to use an annotations-based configuration in the first place, it actually provides the useful ability to generate Java 1.4 compatible source code from annotated Java 5 class files!
We recommend high quality webhost to host and run your jsp application: christian web host services.
Posted in tomcat | No Comments »