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_ko
Articles_pt
Articles_zh




JSPWiki v2.2.33

[RSS]


Hide Menu

XDocletEclipse


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


Eclipse/WSAD Templates

Mirrored from http://www.meagle.com:8080/hibernate_template.jsp

This document provides Eclipse and WebSphere Application Developer IDEs with XDoclet templates that can be used with Hibernate. Click here for installation instructions. For usage click here. Each template shows all parameters that are valid for the XDoclet tag.

Template Name XDoclet Tag
hibarray @hibernate.array
hibbag @hibernate.bag
hibclass @hibernate.class
hibcolelm @hibernate.collection-element
hibcolidx @hibernate.collection-index
hibcolkey @hibernate.collection-key
hibcolmtm @hibernate.many-to-many
hibcolotm @hibernate.one-to-many
hibcomelm @hibernate.collection-composite-element
hibcomp @hibernate.component
hibdisc @hibernate.discriminator
hibid @hibernate.id
hiblist @hibernate.list
hibmap @hibernate.map
hibmto @hibernate.many-to-one
hiboto @hibernate.one-to-one
hibprimarr @hibernate.primitive-array
hibprop @hibernate.property
hibquery @hibernate.query
hibset @hibernate.set
hibsubc @hibernate.subclass
hibts @hibernate.timestamp
hibver @hibernate.version


hibarray back to top
@hibernate.array table="" cascade="save-update"

Parameter Description Mandatory
cascade Specifies which operations should be cascaded from the parent object to the associated object. Valid options are:any|none|save-update|delete|all-delete-orphan false
table The relationship collection table name (not used for one-to-many associations) false
schema Table schema to override the default schema declared on the root element false


hibbag back to top
@hibernate.bag table="" lazy="false" cascade="none" inverse="false"

Parameter Description Mandatory
table The relationship collection table name false
lazy Determines if this is a lazy loading relationship true false
cascade Specifies which operations should be cascaded from the parent object to the associated object. Valid options are:any|none|save-update|delete|all-delete-orphan false
inverse Indicates if this collection is the inverse collection of a bi-directional relationship false
schema Table schema to override the default schema declared on the root element false
order-by (optional, JDK1.4 only) specify a table column (or columns) that define the iteration order of the Map, Set or bag, together with an optional asc or desc false


hibclass back to top
@hibernate.class table="" discriminator-value=""

Parameter Description Mandatory
table The table name associated with this class false
discriminator-value (optional - defaults to the class name): A value that distiguishes individual subclasses, used for polymorphic behaviour. false
jcs-cache caching options : read-write false
mutable (optional, defaults to true): Specifies that instances of the class are (not) mutable. false
schema Table schema to override the default schema declared on the root element false
proxy (optional): Specifies an interface to use for lazy initializing proxies. You may specify the name of the class itself. false


hibcolem back to top
@hibernate.collection-element column="" type="" length=""

Parameter Description Mandatory
column The name of the mapped column false
type The Hibernate type false
length The length of the column false


hibcolidx back to top
@hibernate.collection-index column="" type="" length=""

Parameter Description Mandatory
column The name of the mapped column false
type The Hibernate type false
length The length of the column false


hibcolkey back to top
@hibernate.collection-key column="" generator-class="native"

Parameter Description Mandatory
column The name of the mapped column false
type The Hibernate type false
length The length of the field false
generator-class Names a Java class used to generate unique identifiers for instances of the persistent class. Valid values: increment true
generator-parameter-1 Parameter for key generator class false
generator-parameter-2 Parameter for key generator class false
generator-parameter-3 Parameter for key generator class false


hibcolmtm back to top
   @hibernate.set name="${enclosing_method}" table="link_table_name_here" cascade="save-update" inverse="true|false" lazy="true"
* @hibernate.collection-key column="${enclosing_type}_ID"
* @hibernate.collection-many-to-many class="relationship_class_the_set_contains" column="relationship_foreign_key"
* @return ${return_type}

Parameter Description Mandatory
class The name of the associated class false
column The name of the associated column false


hibcolotm back to top
   @hibernate.set name="${enclosing_method}" table="relationship_table"
* sort="comparator_class" inverse="true|false"
* cascade="save-update" lazy="true"
* @hibernate.collection-key column="${enclosing_type}_ID"
* @hibernate.collection-one-to-many class="relationship_class"
*
* @return ${return_type}

Parameter Description Mandatory
class Fully qualified name of the associated class false


hibcomelm back to top
@hibernate.collection-composite-element class=""

Parameter Description Mandatory
class The fully qualified name of the composite element class true


hibcomp back to top
@hibernate.component class="component_class_name"

Parameter Description Mandatory
class Fully qualified name of the associated class false


hibdisc back to top
@hibernate.discriminator column="subclass" type="character"

Parameter Description Mandatory
column The column used to distinguish the subclass false
type The Hibernate type false
length The length of the column false


hibid back to top
Note: unsaved-value An identifier property value that indicates that an instance
* is newly instantiated (unsaved), distinguishing it from transient instances that
* were saved or loaded in a previous session. If not specified you will get an exception like this:
* another object associated with the session has the same identifier
*
* @hibernate.id generator-class="" type="${return_type}" column="${enclosing_type}_ID"
* unsaved-value="null" length=""
* @return ${return_type}

Parameter Description Mandatory
column (optional - defaults to the property name): The name of the primary key column. false
type The Hibernate type false
length The length of the field false
unsaved-value unsaved-value (optional - defaults to null): An identifier property
value that indicates that an instance is newly instantiated (unsaved),
distinguishing it from transient instances that were saved or loaded
in a previous session.
values - any
false
generator-class Names a Java class used to generate unique identifiers for instances of the persistent class. Valid values: increment(info) false


hibmap back to top
@hibernate.map name="${enclosing_method}" table="relationship-table" lazy="false" cascade="none"

Parameter Description Mandatory
table (optional - defaults to property name) the name of the
collection table (not used for one-to-many associations)
false
lazy (optional - defaults to false) enable lazy initialization
(not used for arrays)
false
cascade (optional - defaults to none) enable operations to cascade to child entities false
schema (optional) the name of a table schema to override the schema declared on the root element false
sort (optional) specify a sorted collection with natural sort order, or a given comparator class false
order-by (optional, JDK1.4 only) specify a table column (or columns) that
define the iteration order of the Map, Set or bag, together with
an optional asc or desc
false
name The collection property name false


hibmto back to top
@hibernate.many-to-one column="${return_type}_ID" class="package.${return_type}"
*
* @return ${return_type}
*

Parameter Description Mandatory
name The name of the property. false
column (optional): The name of the column. false
class (optional - defaults to the property type determined by reflection): The name of the associated class. false
cascade (optional): Specifies which operations should be cascaded from the parent object to the associated object. false
outer-join (optional - defaults to auto): enables outer-join fetching for this association when hibernate.use_outer_join is set. false
update, insert (optional - defaults to true) specifies that the mapped columns should be included in SQL UPDATE and/or INSERT statements. Setting both to false allows a pure "derived" association whose value is initialized from some other property that maps to the same colum(s) or by a trigger or other application. false


hiboto back to top
hibernate.one-to-one cascade="none" class="" outer-join="auto"

Parameter Description Mandatory
class (optional - defaults to the property type determined by reflection): The name of the associated class. false
cascade (optional) specifies which operations should be cascaded from the parent object to the associated object. false
outer-join (optional - defaults to auto): Enable outer-join fetching for this association when hibernate. use_outer_join is set. false


hibprimarr back to top
@hibernate.primitive-array table="" cascade="none"

Parameter Description Mandatory
table The name of the table false
schema schema (optional) the name of a table schema to override the schema
declared on the root element
false
cascade (optional - defaults to none) enable operations to cascade to child entities
values - all
false


hibprop back to top
@hibernate.property name="${enclosing_method}" column="${enclosing_method}" type="${return_type}" not-null="false" unique="false"
*
* @return ${return_type}

Parameter Description Mandatory
name the name of the property, with an initial lowercase letter. false
column (optional - defaults to the property name): the name of the mapped database table column. false
type (optional): a name that indicates the Hibernate type. false
length The length of the mapped database table column. false
not-null If the column is not nullable false
unique If the column is unique false


hibquery back to top
@hibernate.query name="" query=""

Parameter Description Mandatory
name The name of the query false
query The HQL query statement false


hibset back to top
@hibernate.set name="${enclosing_method}" table="relationship_table"
* sort="comparator_class" inverse="true"
* cascade="save-update" lazy="true"

Parameter Description Mandatory
name the name of the property, with an initial lowercase letter. false
table The name of the association table false
sort The fully qualified comparator class (optional) false
inverse Indicates if this collection is the inverse collection of a bi-directional relationship false
cascade Specifies which operations should be cascaded from the parent object to the associated object. Valid options are:any|none|save-update|delete|all-delete-orphan false
lazy (optional - defaults to false) enable lazy initialization
(not used for arrays)
false
schema schema (optional) the name of a table schema to override the schema
declared on the root element
false


hibsubc back to top
@hibernate.subclass name="" discriminator-value=""

Parameter Description Mandatory
name The fully qualified class name of the subclass. false
discriminator-value (optional - defaults to the class name): A value that distiguishes individual subclasses. false
proxy (optional): Specifies a class or interface to use for lazy initializing proxies. false


hibts back to top
@hibernate.timestamp column="${enclosing_method}"
*
* @return ${return_type}

Parameter Description Mandatory
column The name of the column that contains the timestamp false


hibver back to top
@hibernate.version column="${enclosing_method}"
*
* @return ${return_type}

Parameter Description Mandatory
column The name of a column holding the version number. false


Installation

To install these templates into Eclipse/WSAD follow these instructions.

  1. Download the template file and save it in a local directory.
  2. Start Eclipse/WSAD IDE
  3. Select Window/Preferences
  4. Expand Java/Editor/Templates
  5. Click Import
  6. Browse for the downloaded file in step 1 and click OK


Usage

Here is a simple example of how add a couple of Hibernate XDoclet tags to a class file. This will demonstrate how to add a class tag and property tag to a Hibernate class using these templates:

Let's start with a simple class file called Project.

package com.meagle

/**
* This class represents a project
*
* @author MEagle
*/
public class Project {

}
To add the class Xdoclet tags position your cursor inside the class javadoc section and type hib and then press CTRL + SPACE to bring up code completion. Scroll down until you locate hibclass and press the enter key. The more characters that are typed the faster you will code complete. Here is what you will see in the editor:

Notice that the table attribute autopopulated a default table name based on the name of the class. You can accept this entry or override it with your own table name.

Now let's add a property to this class called name. To do this add a new property to the class. Then highlight the field (name) and right click and select 'Source'/'Generate Setter and Getter...'. Then click OK to generate the accessor and mutator methods. Here is what you should see at this point:

package com.meagle

/**
* This class represents a project
*
* @hibernate.class table="Project"
*
* @author MEagle
*/
public class Project {

private String name;
/**
* @return
*/
public String getName() {
return name;
}

/**
* @param string
*/
public void setName(String string) {
name = string;
}
}


Now we need to insert the property tag for the field name. Position your cursor in the javadoc section of getName. Type hibp and press CTRL + SPACE to bring up code completion. Scroll down until you locate hibprop and press the enter key. Here is what you should see now:

package com.meagle

/**
* This class represents a project
*
* @hibernate.class table="Project"
*
* @author MEagle
*/
public class Project {

private String name;

/**
* @return
*/
public String getName() {
return name;
}

/**
* @param string
*/
public void setName(String string) {
name = string;
}
}
Because Eclipse does not provide the return type you will need to manually delete the default @return tag that does not contain the return type. Here is the generated code:

package com.meagle

/**
* This class represents a project
*
* @hibernate.class table="Project"
*
* @author MEagle
*/
public class Project {

private String name;

/**
* @hibernate.property name="getName" column="getName" type="String" not-null="false" unique="false"
*
* @return String
*/
public String getName() {
return name;
}

/**
* @param string
*/
public void setName(String string) {
name = string;
}
}


Unfortunately the Eclipse template builder is not robust enough to get exactly what we need. Notice that the value for the column attribute and the name attribute is 'getName'. Because there is no way to substring this value you will have to manually rename these values to 'name' or another value. I tried to at least populate the attributes as closely as possible. If this is an annoyance you can modify the template(s) to remove this behaviour. Here is what the final code looks like:

package com.meagle

/**
* This class represents a project
*
* @hibernate.class table="Project"
*
* @author MEagle
*/
public class Project {

private String name;

/**
* @hibernate.property name="name" column="Name" type="String" not-null="false" unique="false"
*
* @return String
*/
public String getName() {
return name;
}

/**
* @param string
*/
public void setName(String string) {
name = string;
}
}


From this point you should use Ant and the HibernateDoclet task to generate the Hibernate mapping files from the XDoclet embedded in your .java files.


Attachments:
templates.xml Info on templates.xml 5786 bytes


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