Skip to content

Commit 96ffd45

Browse files
committed
pom.xml(hibernate3-maven-plugin): allow to auto generare DDL for MySQL in dev environment.
You should run mvn -P dev clean compile hibernate3:hbm2ddl to generate scheme for MySQL which will be writed to src/env/dev/WEB-INF/classes/mysql-scheme.sql file.
1 parent 4a5008b commit 96ffd45

File tree

3 files changed

+120
-140
lines changed

3 files changed

+120
-140
lines changed

pom.xml

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,68 @@
378378
</executions>
379379
</plugin>
380380

381+
<plugin>
382+
<groupId>org.codehaus.mojo</groupId>
383+
<artifactId>hibernate3-maven-plugin</artifactId>
384+
<version>2.2</version>
385+
<configuration>
386+
<components>
387+
<component>
388+
<name>hbm2ddl</name>
389+
<implementation>jpaconfiguration</implementation>
390+
<outputDirectory>${env.dir}</outputDirectory>
391+
</component>
392+
</components>
393+
<componentProperties>
394+
<console>false</console>
395+
<format>true</format>
396+
<jdk5>true</jdk5>
397+
<propertyfile>
398+
${env.dir}/spring/database.properties
399+
</propertyfile>
400+
<outputfilename>${ddl.file}</outputfilename>
401+
402+
<!--
403+
Don't try to connect to database. See:
404+
http://www.mail-archive.com/users@maven.apache.org/msg61394.html
405+
-->
406+
<export>false</export>
407+
</componentProperties>
408+
</configuration>
409+
<dependencies>
410+
<!--
411+
Use latest version of Hibernate. See:
412+
http://stackoverflow.com/q/2734971
413+
-->
414+
<dependency>
415+
<groupId>org.hibernate</groupId>
416+
<artifactId>hibernate-core</artifactId>
417+
<version>${hibernate.version}</version>
418+
</dependency>
419+
<dependency>
420+
<groupId>org.hibernate</groupId>
421+
<artifactId>hibernate-entitymanager</artifactId>
422+
<version>${hibernate.version}</version>
423+
</dependency>
424+
<dependency>
425+
<groupId>javax.validation</groupId>
426+
<artifactId>validation-api</artifactId>
427+
<version>1.0.0.GA</version>
428+
</dependency>
429+
<!--
430+
Explicitly add dependency to jboss-logging (which used by
431+
hibernate-validator since 4.3.0) to prevent following error:
432+
"Unable to get the default Bean Validation factory: InvocationTargetException:
433+
org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object"
434+
-->
435+
<dependency>
436+
<groupId>org.jboss.logging</groupId>
437+
<artifactId>jboss-logging</artifactId>
438+
<version>3.1.1.GA</version>
439+
</dependency>
440+
</dependencies>
441+
</plugin>
442+
381443
<plugin>
382444
<groupId>com.mycila.maven-license-plugin</groupId>
383445
<artifactId>maven-license-plugin</artifactId>
@@ -588,6 +650,7 @@
588650
</activation>
589651
<properties>
590652
<env.dir>${env.root.dir}/dev/WEB-INF/classes</env.dir>
653+
<ddl.file>mysql-scheme.sql</ddl.file>
591654
</properties>
592655
<dependencies>
593656
<dependency>
@@ -653,6 +716,7 @@
653716
</activation>
654717
<properties>
655718
<env.dir>${env.root.dir}/test/WEB-INF/classes</env.dir>
719+
<ddl.file>h2-scheme.sql</ddl.file>
656720
</properties>
657721
<dependencies>
658722
<dependency>
@@ -736,68 +800,6 @@
736800
</executions>
737801
</plugin>
738802

739-
<plugin>
740-
<groupId>org.codehaus.mojo</groupId>
741-
<artifactId>hibernate3-maven-plugin</artifactId>
742-
<version>2.2</version>
743-
<configuration>
744-
<components>
745-
<component>
746-
<name>hbm2ddl</name>
747-
<implementation>jpaconfiguration</implementation>
748-
<outputDirectory>${env.dir}</outputDirectory>
749-
</component>
750-
</components>
751-
<componentProperties>
752-
<console>false</console>
753-
<format>true</format>
754-
<jdk5>true</jdk5>
755-
<propertyfile>
756-
${env.dir}/spring/database.properties
757-
</propertyfile>
758-
<outputfilename>h2-scheme.sql</outputfilename>
759-
760-
<!--
761-
Don't try to connect to database. See:
762-
http://www.mail-archive.com/users@maven.apache.org/msg61394.html
763-
-->
764-
<export>false</export>
765-
</componentProperties>
766-
</configuration>
767-
<dependencies>
768-
<!--
769-
Use latest version of Hibernate. See:
770-
http://stackoverflow.com/q/2734971
771-
-->
772-
<dependency>
773-
<groupId>org.hibernate</groupId>
774-
<artifactId>hibernate-core</artifactId>
775-
<version>${hibernate.version}</version>
776-
</dependency>
777-
<dependency>
778-
<groupId>org.hibernate</groupId>
779-
<artifactId>hibernate-entitymanager</artifactId>
780-
<version>${hibernate.version}</version>
781-
</dependency>
782-
<dependency>
783-
<groupId>javax.validation</groupId>
784-
<artifactId>validation-api</artifactId>
785-
<version>1.0.0.GA</version>
786-
</dependency>
787-
<!--
788-
Explicitly add dependency to jboss-logging (which used by
789-
hibernate-validator since 4.3.0) to prevent following error:
790-
"Unable to get the default Bean Validation factory: InvocationTargetException:
791-
org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object"
792-
-->
793-
<dependency>
794-
<groupId>org.jboss.logging</groupId>
795-
<artifactId>jboss-logging</artifactId>
796-
<version>3.1.1.GA</version>
797-
</dependency>
798-
</dependencies>
799-
</plugin>
800-
801803
</plugins>
802804
</build>
803805
</profile>
Lines changed: 53 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,59 @@
1-
CREATE DATABASE mystamps;
2-
USE mystamps;
1+
---
2+
--- Generated by maven: mvn -P dev clean compile hibernate3:hbm2ddl
3+
---
34

4-
----
5-
-- users
6-
-- (see ru.mystamps.web.entity.User)
7-
----
8-
CREATE TABLE `users` (
9-
`id` INT(5) UNSIGNED AUTO_INCREMENT NOT NULL,
10-
`login` VARCHAR(15) NOT NULL,
11-
`name` VARCHAR(100) NOT NULL,
12-
13-
-- see email field at users_activation
14-
`email` VARCHAR(255) NOT NULL,
15-
16-
`registered_at` DATETIME NOT NULL,
17-
`activated_at` DATETIME NOT NULL,
18-
19-
`hash` VARCHAR(40) NOT NULL,
20-
21-
-- see ru.mystamps.web.service.UserService.generateSalt()
22-
`salt` VARCHAR(10) NOT NULL,
23-
24-
PRIMARY KEY(`id`),
25-
UNIQUE KEY(`login`)
26-
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
5+
create table countries (
6+
id integer not null auto_increment,
7+
created_at datetime not null,
8+
name varchar(50) not null unique,
9+
primary key (id)
10+
) ENGINE=InnoDB;
2711

28-
----
29-
-- users_activation
30-
-- (see ru.mystamps.web.entity.UsersActivation)
31-
----
32-
CREATE TABLE `users_activation` (
33-
-- see:
34-
-- ACT_KEY_LENGTH in WEB-INF/web.xml
35-
-- ru.mystamps.web.service.UserService.generateActivationKey()
36-
`act_key` VARCHAR(10) NOT NULL,
37-
38-
`email` VARCHAR(255) NOT NULL,
39-
`created_at` DATETIME NOT NULL,
40-
41-
PRIMARY KEY(`act_key`)
42-
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
12+
create table suspicious_activities (
13+
id integer not null auto_increment,
14+
ip varchar(15) not null,
15+
occured_at datetime not null,
16+
page varchar(100) not null,
17+
referer_page varchar(255) not null,
18+
user_agent varchar(255) not null,
19+
type_id integer not null,
20+
user_id integer,
21+
primary key (id)
22+
) ENGINE=InnoDB;
4323

44-
----
45-
-- suspicious_activities_types
46-
-- (see ru.mystamps.web.entity.SuspiciousActivityType)
47-
----
48-
CREATE TABLE `suspicious_activities_types` (
49-
`id` INT(5) UNSIGNED AUTO_INCREMENT NOT NULL,
50-
`name` VARCHAR(100) NOT NULL,
51-
PRIMARY KEY(`id`),
52-
UNIQUE KEY(`name`)
53-
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
24+
create table suspicious_activities_types (
25+
id integer not null auto_increment,
26+
name varchar(100) not null unique,
27+
primary key (id)
28+
) ENGINE=InnoDB;
5429

55-
----
56-
-- suspicious_activities
57-
-- (see ru.mystamps.web.entity.SuspiciousActivity)
58-
----
59-
CREATE TABLE `suspicious_activities` (
60-
`id` INT(5) UNSIGNED AUTO_INCREMENT NOT NULL,
61-
`type_id` INT(5) UNSIGNED NOT NULL,
62-
`occured_at` DATETIME NOT NULL,
63-
`page` VARCHAR(100) NOT NULL,
64-
`user_id` INT(5) UNSIGNED,
65-
`ip` VARCHAR(15) NOT NULL DEFAULT '',
66-
`referer_page` VARCHAR(255) NOT NULL DEFAULT '',
67-
`user_agent` VARCHAR(255) NOT NULL DEFAULT '',
68-
PRIMARY KEY(`id`),
69-
FOREIGN KEY(`type_id`) REFERENCES `suspicious_activities_types`(`id`) ON UPDATE CASCADE ON DELETE CASCADE,
70-
FOREIGN KEY(`user_id`) REFERENCES `users`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
71-
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
30+
create table users (
31+
id integer not null auto_increment,
32+
activated_at datetime not null,
33+
email varchar(255) not null,
34+
hash varchar(40) not null,
35+
login varchar(15) not null unique,
36+
name varchar(100) not null,
37+
registered_at datetime not null,
38+
salt varchar(10) not null,
39+
primary key (id)
40+
) ENGINE=InnoDB;
7241

73-
----
74-
-- countries
75-
-- (see ru.mystamps.web.entity.Country)
76-
----
77-
CREATE TABLE `countries` (
78-
`id` INT(5) UNSIGNED AUTO_INCREMENT NOT NULL,
79-
`name` VARCHAR(50) NOT NULL,
80-
`created_at` DATETIME NOT NULL,
81-
PRIMARY KEY(`id`),
82-
UNIQUE KEY(`name`)
83-
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
42+
create table users_activation (
43+
act_key varchar(10) not null,
44+
created_at datetime not null,
45+
email varchar(255) not null,
46+
primary key (act_key)
47+
) ENGINE=InnoDB;
8448

49+
alter table suspicious_activities
50+
add index FK35F0CA0F8D3FBEA4 (user_id),
51+
add constraint FK35F0CA0F8D3FBEA4
52+
foreign key (user_id)
53+
references users (id);
54+
55+
alter table suspicious_activities
56+
add index FK35F0CA0FC005E970 (type_id),
57+
add constraint FK35F0CA0FC005E970
58+
foreign key (type_id)
59+
references suspicious_activities_types (id);

src/env/dev/WEB-INF/classes/spring/database.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ jpa.dialectClassName=org.hibernate.dialect.MySQL5InnoDBDialect
66
jpa.showSql=true
77
hibernate.formatSql=true
88
hibernate.hbm2ddl.auto=validate
9+
10+
# needed for hibernate3-maven-plugin
11+
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

0 commit comments

Comments
 (0)