Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Articles
Articles_cn
Articles_de
Articles_pt
Articles_zh
HibernateRelationshi...




JSPWiki v2.2.33

[RSS]


Hide Menu

HibernateRelationships


This is version 9. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]


About this tutorial

This is a tutorial to show how to create and manage Hibernate relationships within AppFuse. This tutorial was written for AppFuse 1.8 and the AppGen pieces may not work with previous versions.

Table of Contents

  • [1] Create Weblog.java, Entry.java and add XDoclet tags
  • [2] [Many-to-One] Create a new Category object and modify Entry.java to use it
  • [3] [One-to-Many] A Weblog object can have many Entries
  • [4] [Many-to-Many] ???
  • [5] Lazy-Loading Issues
  • [6] Managing relationships and indexed properties in the UI

Create Weblog.java, Entry.java and add XDoclet tags [#1]

For our purposes, the Weblog entity is a list of available weblogs. A “Weblog” object has the following properties – an id, a username, a dateCreated, and a blogTitle. Every Entry object has an id, a text, and a timeCreated property. The first thing to do is create some objects to persist. Let's create both a "Weblog" object and an “Entry” object (in the src/dao/**/model directory).


package org.appfuse.model;

public class Weblog extends BaseObject {
  private Long id;
  private String username;
  private Date dateCreated;
  private Date blogTitle;


    /*
     Generate your getters and setters using your favorite IDE: 
     In Eclipse:
     Right-click -> Source -> Generate Getters and Setters
    */
}


package org.appfuse.model;

import java.util.Date;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * @hibernate.class table="entry"
 */
public class Entry extends BaseObject {

  private Long id;
  private String text;
  private Date timeCreated;
  private Integer version;
/**
   @return Returns the id.
   
   * @hibernate.id column="entry_id" generator-class="native"
   *               unsaved-value="null"
   */
  public Long getId() {
    return id;
  }

  /**
   @param id
   *            The id to set.
   */
  public void setId(Long id) {
    this.id = id;
  }

  /**
   @return Returns the text.
   
   * @hibernate.property column="text"
   */
  public String getText() {
    return text;
  }

  /**
   @param text
   *            The text to set.
   */
  public void setText(String text) {
    this.text = text;
  }

  /**
   @return Returns the timeCreated.
   
   * @hibernate.property column="time_create"
   */
  public Date getTimeCreated() {
    return timeCreated;
  }

  /**
   @param timeCreated
   *            The timeCreated to set.
   */
  public void setTimeCreated(Date timeCreated) {
    this.timeCreated = timeCreated;
  }

  /**
   @return Returns the version.
   
   * @hibernate.version
   */
  public Integer getVersion() {
    return version;
  }

  /**
   @param version
   *            The version to set.
   */
  public void setVersion(Integer version) {
    this.version = version;
  }

  /**
   @see java.lang.Object#equals(Object)
   */
  public boolean equals(Object object) {
    if (!(object instanceof Entry)) {
      return false;
    }
    Entry rhs = (Entryobject;
    return new EqualsBuilder().append(this.text, rhs.text).append(
        this.timeCreated, rhs.timeCreated).append(this.id, rhs.id)
        .append(this.version, rhs.version).isEquals();
  }

  /**
   @see java.lang.Object#hashCode()
   */
  public int hashCode() {
    return new HashCodeBuilder(-880342185, -1668369001).append(this.text)
        .append(this.timeCreated).append(this.id).append(this.version)
        .toHashCode();
  }

  /**
   @see java.lang.Object#toString()
   */
  public String toString() {
    return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
        .append("text"this.text).append("id"this.id).append(
            "version"this.version).append("timeCreated",
            this.timeCreated).toString();
  }

}

[Many-to-One] Create a new Category object and modify Entry.java to use it [#2]

[One-to-Many] A Weblog object can have many Entries [#3]

[Many-to-Many] ??? [#4]

Lazy-Loading Issues [#5]

Managing relationships and indexed properties in the UI [#6]


Attachments:
Category.java Info on Category.java 1985 bytes
Entry.java Info on Entry.java 1947 bytes
Weblog.java Info on Weblog.java 2066 bytes
ER-Diagram.jpg Info on ER-Diagram.jpg 31720 bytes
LazyDAOTests.diff Info on LazyDAOTests.diff 4070 bytes


Go to top   More info...   Attach file...
This particular version was published on 06-Nov-2006 13:52:44 MST by RanceShields.