XDocletEclipse |
|
Your trail: |
This is version 1.
It is not the current version, and thus it cannot be edited.
[Back to current version]
[Restore this version]
Eclipse/WSAD Templates
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.
@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
|
|
@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
|
|
@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
|
|
@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
|
|
@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
|
|
@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
|
|
@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
|
|
@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
|
|
@hibernate.collection-composite-element
class=""
|
Parameter
|
Description
|
Mandatory
|
class
|
The fully qualified name of the composite element class
|
true
|
|
@hibernate.component
class="component_class_name"
|
Parameter
|
Description
|
Mandatory
|
class
|
Fully qualified name of the associated class
|
false
|
|
@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
|
|
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
|
false
|
|
@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
|
|
@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
|
|
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
|
|
@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
|
|
@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
|
|
@hibernate.query name="" query=""
|
Parameter
|
Description
|
Mandatory
|
name
|
The name of the query
|
false
|
query
|
The HQL query statement
|
false
|
|
@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
|
|
@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
|
|
@hibernate.timestamp
column="${enclosing_method}"
*
* @return ${return_type}
|
Parameter
|
Description
|
Mandatory
|
column
|
The name of the column that contains the timestamp
|
false
|
|
@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.
-
Download the template file and save it
in a local directory.
-
Start Eclipse/WSAD IDE
-
Select Window/Preferences
-
Expand Java/Editor/Templates
-
Click Import
-
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:
|