What sort of database will I get with an Apache Wicket Application?

So I've done my Object Oriented design, put together a database schema to go with my design, and promised an impossibly short deadline for delivery I've decided to make my life "easier" by using a Web Framework.

Spring seems insanely complicated (and rather inelegant at a superficial glance) and Roo is impossible to understand and/or get help with on the forums beyond doing anything beyond a basic CRUD app.

I am using (and learning!) Wicket then to accomplish my task. I am spending a lot of time trying to figure out how Wicket creates and uses the database and if I understand correctly it does this automagically from the POJOs that I will be creating. I creating objects that use objects in moderately complex ways, however, and I would like to have a better idea of what the end result is going to look like in mySQL.

Does anyone have any information or links that explain what resulting schema looks like from a Wicket application?

Answers


It seems to me like you are coming from the PHP or .Net world and are not used to the way things work in Java (with the emphasis on work). In short: there is no free lunch and if you just glance at Spring or Roo and conclude these are too complicated, you might have some rough times ahead. Java offers a lot of frameworks and flexibility, but you have to do the work.

That said, I love Wicket although it does have somewhat of a learning curve. Wicket has a great approach to templating and resolving all business and control logic in actual Java code. Also, Wicket has an active community with very extensive documentation, wiki's and examples. Wicket does, as Joril pointed out, not do anything related to Object Relational Mapping (ORM) or persistence in general AFAIK. There might be extensions or Wicket-related projects that offer something for this.

Here is my advice for you on how to tackle this: Use Maven2 and Spring (yes, Spring) and import the following dependencies in your pom.xml:

<properties>
    <spring.version>3.0.0.RELEASE</spring.version>
    <wicket.version>1.4.10</wicket.version>
</properties>

<dependencyManagement>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.context</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.orm</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>com.springsource.org.apache.commons.dbcp</artifactId>
    <version>1.2.2.osgi</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>com.springsource.org.apache.commons.pool</artifactId>
    <version>1.5.3</version>
    <scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.mysql.jdbc</groupId>
    <artifactId>com.springsource.com.mysql.jdbc</artifactId>
    <version>5.1.6</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>com.springsource.org.hibernate</artifactId>
    <version>3.3.2.GA</version>
</dependency>
<dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>com.springsource.javax.persistence</artifactId>
    <version>1.0.0</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>com.springsource.org.hibernate.annotations</artifactId>
    <version>3.4.0.GA</version>
    <exclusions>
        <exclusion>
        <groupId>org.apache.commons</groupId>
        <artifactId>com.springsource.org.apache.commons.logging</artifactId>
    </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.wicket</groupId>
    <artifactId>wicket</artifactId>
    <version>${wicket.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.wicket</groupId>
    <artifactId>wicket-spring</artifactId>
    <version>${wicket.version}</version>
    <exclusions>
        <exclusion>
        <artifactId>spring</artifactId>
        <groupId>org.springframework</groupId>
    </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.wicket</groupId>
    <artifactId>wicket-extensions</artifactId>
    <version>${wicket.version}</version>
</dependency>

Annotate your model classes with JPA/Hibernate annotations like so (just an example that shows several common constructs):

@Entity(name = "User")
@Table(name = "users", uniqueConstraints = { @UniqueConstraint(columnNames = { "email" }) })
@SecondaryTable(name = "user_picture")
public class User implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String email;
    private String name;
    private String password;
    @Lob
    @Column(table = "users_picture", length = 524288)
    private byte[] picture;
    private Date birthDate;
    private String phonenumber;
    @ManyToOne(fetch = FetchType.EAGER)
    private Address homeAddress;
    @Enumerated(EnumType.STRING)
    private Gender gender;  
    @CollectionOfElements(fetch = FetchType.EAGER)
    @Enumerated(EnumType.STRING)
    private Set<Weekday> workdays = new HashSet<Weekday>();

Use the hibernate3-maven-plugin to generate your database from your annotated model classes. This is a huge time saver. The database gets generated during the test phase of maven2. There are other plugins (DBUnit) that help you to fill your database with test data or the like (you can use old school .sql scripts as well). If you change something in your model, the change automatically propagates to your database (after a maven build of course) which is great during development.

Add this to your pom (I prefer making a multi-module maven project with modules for frontend, backend and api; this would go into your backend pom):

<build>
<plugins>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>2.0-alpha-1</version>
    <configuration>
        <components>
            <component>
            <name>hbm2ddl</name>
            <implementation>
                annotationconfiguration
                </implementation>
        </component>
        </components>
        <componentProperties>
            <drop>true</drop>
        <jdk5>true</jdk5>
        <propertyfile>
            target/classes/jdbc.properties
            </propertyfile>
        <skip>${maven.test.skip}</skip>
        </componentProperties>
        </configuration>
        <executions>
            <execution>
            <phase>process-test-resources</phase>
                <goals>
                <goal>hbm2ddl</goal>
            </goals>
            </execution>
         </executions>
         <dependencies>
             <dependency>
             <groupId>mysql</groupId>
                 <artifactId>mysql-connector-java</artifactId>
                 <version>5.0.5</version>
         </dependency>
         </dependencies>
    </plugin>
</plugins>

This is what the generated table would look like:

+--------------------------------+--------------+------+-----+---------+----------------+
| Field                          | Type         | Null | Key | Default | Extra          |
+--------------------------------+--------------+------+-----+---------+----------------+
| id                             | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| email                          | varchar(255) | YES  | UNI | NULL    |                |
| name                           | varchar(255) | YES  |     | NULL    |                |
| password                       | varchar(255) | YES  |     | NULL    |                |
| birthDate                      | datetime     | YES  |     | NULL    |                |
| phonenumber                    | varchar(255) | YES  |     | NULL    |                |
| gender                         | varchar(255) | YES  |     | NULL    |                |
| address                        | bigint(20)   | YES  | MUL | NULL    |                |
+--------------------------------+--------------+------+-----+---------+----------------+

(users_workdays and users_picture are secondary tables referring to this entity)

All my examples are based on the use of a MySQL database; you can replace with with any old RDBMS.

I hope this helps you a) to wake up and smell the ashes, b) get your Wicket project up to speed ORM-wise

cheers!


It's been 2+ years since I last used Wicket, but AFAIK it doesn't handle persistence at all.. While Wicket is a very good framework IMHO, you have to handle the database layer yourself with Hibernate or some other ORM (or no ORM at all, of course)


Need Your Help

MySQL Timestamp format

mysql sql date timestamp date-format

I have exported my database to a CSV file and the timestamp now liiks like this:

Using XmlSerializer and setting root class name

c# xml xml-parsing .net-4.5

Trying to work with XmlSerializer to nicely deserialize stuff I get from webservice.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.