Reworked documentation: splited and reorderd pages and menu
[hibernate4-maven-plugin] / src / site / apt / configuration.apt
1 Configuration Examples
2
3 * Configuration through a hibernate.properties-File
4
5   The most simple way to configure the plugin is, to put all the
6   hibernate-configuration in a <<hibernate.properties>>-file on your
7   classpath. Put the file in the <<<resources>>>-folder. Maven will put
8   it in the <<<class>>>-folder of your webapp, where it will be picked up
9   by this plugin as well as by Hibernate 4.
10
11   Doing so, the only additionally configuration needed, to activat the plugin
12   is the following entry in the <<<plugins>>>-section of your <<<pom.xml>>>:
13
14 ---------------
15 <plugin>
16   <groupId>de.juplo</groupId>
17   <artifactId>hibernate4-maven-plugin</artifactId>
18   <version>${project.version}</version>
19   <executions>
20     <execution>
21       <goals>
22         <goal>export</goal>
23       </goals>
24     </execution>
25   </executions>
26 </plugin>
27 ---------------
28
29   But be aware, that in this case the database-url, that is
30   build in the application is the same that is used while testing, where
31   the database is droped and recreated by the plugin.
32   <<<So, you should never fire up this configuration on your production
33   system, or your database might be erased!>>>
34
35   Hence, you should specify a different url for testing like in the
36   following snippet:
37
38 ---------------
39 <plugin>
40   <groupId>de.juplo</groupId>
41   <artifactId>hibernate4-maven-plugin</artifactId>
42   <version>${project.version}</version>
43   <executions>
44     <execution>
45       <goals>
46         <goal>export</goal>
47       </goals>
48     </execution>
49   </executions>
50   <configuration>
51     <url><![CDATA[jdbc:mysql://localhost/test-db]]></url>
52   </configuration>
53 </plugin>
54 ---------------
55
56   Configuration properties, that are set in the <<<configuration>>>-section
57   of the plugin-configuration cannnot be overwritten elsewere (for details
58   see {{Configuration-Method-Precedence}}).
59   You never can overwrite them by accident when specifying a property on
60   the commandline or in your <<<settings.xml>>>.
61
62 * Configuration through maven-properties
63
64   Alternatively, it is possible, to configure the plugin via maven-properties.
65   Each relevant configuration-option has a corresponding maven-property
66   (for a full list see the {{{./export-mojo.html} Documentation of the export-Mojo}}).
67   These are named after the
68   {{{http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc} Hibernate JDBC Properties}}:
69
70     * <<<hibernate.connection.driver_class>>>
71
72     * <<<hibernate.dialect>>>
73
74     * <<<hibernate.connection.url>>>
75
76     * <<<hibernate.connection.username>>>
77
78     * <<<hibernate.connection.password>>>
79
80   So, instead of writing the hibernate-configuration in the properties-file,
81   like above, you could put it in the <<<properties>>>-section of your
82   <<<pom.xml>>>.
83
84   Thogether with the plugin-definition from above, the following would
85   be a complete configuration (again, the database-url was overwritten in
86   the plugin-configuration, to be sure to have a separate database for
87   testing):
88
89 ---------------
90 <properties>
91   <hibernate.connection.driver_class>org.hsqldb.jdbcDriver</hibernate.connection.driver_class>
92   <hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
93   <hibernate.connection.url><![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]></hibernate.connection.url>
94   <hibernate.connection.username>sa</hibernate.connection.username>
95   <hibernate.connection.password></hibernate.connection.password>
96 </properties>
97
98 ...
99
100 <plugins>
101
102   ...
103
104   <plugin>
105     <groupId>de.juplo</groupId>
106     <artifactId>hibernate4-maven-plugin</artifactId>
107     <version>${project.version}</version>
108     <executions>
109       <execution>
110         <goals>
111           <goal>export</goal>
112         </goals>
113       </execution>
114     </executions>
115     <configuration>
116       <url><![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></url>
117     </configuration>
118   </plugin>
119
120 <plugins>
121 ---------------
122
123 * Configuration through the plugin-configuration
124
125   A third way for configuring the plugin is the plugin-configuration.
126   The relevant configuration-parameters are:
127
128     * <<<driverClassName>>>
129
130     * <<<hibernateDialect>>>
131
132     * <<<url>>>
133
134     * <<<username>>>
135
136     * <<<password>>>
137
138   The equivalent of the configuration from the last section would look
139   like this:
140
141 ---------------
142 <plugin>
143   <groupId>de.juplo</groupId>
144   <artifactId>hibernate4-maven-plugin</artifactId>
145   <version>${project.version}</version>
146   <executions>
147     <execution>
148       <goals>
149         <goal>export</goal>
150       </goals>
151     </execution>
152   </executions>
153   <configuration>
154     <driverClassName>org.hsqldb.jdbcDriver</driverClassName>
155     <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>
156     <url><![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]></url>
157     <username>sa</username>
158     <password></password>
159   </configuration>
160 </plugin>
161 ---------------
162
163   There are some seldom used parameters, that can only be configured throug
164   this method:
165
166     * <<delimiter>> the delimiter used in the generated sql-script
167
168     * <<format>> wether the generated sql-script is formatted, or not
169
170     * <<hibernateProperties>> name of the hibernate-properties-file
171
172     * <<outputFile>> name of the generated sql-script
173
174     * <<target>> create database or generate sql-script or both
175
176     * <<type>> create or drop the database or do both or nothing
177       (just validate the annotation-configuration)
178
179   For explanations, see the
180   {{{./export-mojo.html} Documentation of the export-Mojo}}.
181
182 {Configuration-Method-Precedence}
183
184   The configuration is gathered in a fix order:
185
186     [[1]] <<<hibernate.properties>>>
187
188     [[2]] maven-properties
189
190     [[3]] plugin-configuration
191
192   If you are in doubt about where a configuration-value comes from, run
193   maven with the {{{./debugging.html}debug-output}} enabled: <<<mvn -X hibernate4:export>>>
194   and be aware, that maven-properties can be overwitten on the command-line,
195   in your <<<~/.m2/settings.xml>>> and in a profile.
196
197   The plugin-configuration comes last and overwrites everything else.
198   That way, you can be sure, that a configuration-value, that is
199   specified in the plugin-configuration will never be overwritten by any
200   other configuration-method.
201
202
203   If you realy need to overwrite plugin-configuration-values with
204   maven-properties, you can use maven-properties in the plugin-configuration:
205
206 ----------------
207 <plugin>
208   <groupId>de.juplo</groupId>
209   <artifactId>hibernate4-maven-plugin</artifactId>
210   <version>${project.version}</version>
211   <executions>
212     <execution>
213       <goals>
214         <goal>export</goal>
215       </goals>
216     </execution>
217   </executions>
218   <configuration>
219     <password>${my-password-property}</password>
220   </configuration>
221 </plugin>
222 ----------------