EJBGen

An EJB 2.0 code generator

Current Version: 2.18

Cedric Beust

Created January 5, 2001
Last modified April 28th, 2004

Please note that the version of EJBGen on this Web site is not supported by BEA. You should use the version shipped with WebLogic Server if you want to get support from BEA for anything you download from this Web site.

Table of contents

Introduction

EJBGen is an Enterprise JavaBeans 2.0 code generator. Instead of having to edit and maintain several files (Bean, Remote and Home classes, and the deployment descriptors), EJBGen will allow you to limit your editing to one file (the Bean class) and annotate it with Javadoc tags. EJBGen will then parse your source and will generate all the needed files.

If you are upgrading from an older version or if you're just checking this page for new stuff, see the What's New section.

EJBGen generates code suitable for EJB 2.0 and features:

You can either download the latest version of EJBGen or download older versions.

Here is a short example to illustrate EJBGen (a full example is also available). AccountBean.java is your main bean class. It is a CMP EJB 2.0 Entity bean:

/**
 * @ejbgen:entity
 *   ejb-name = AccountEJB-OneToMany
 *   data-source-name = examples-dataSource-demoPool
 *   table-name = Accounts
 *   prim-key-class = java.lang.String
 *
 * @ejbgen:jndi-name
 *   local = one2many.AccountHome

 * @ejbgen:finder
 *   signature = "Account findAccount(double balanceEqual)"
 *   ejb-ql = "SELECT OBJECT(h) FROM AccountEJB AS h WHERE balance = ?1"
 *
 * @ejbgen:finder
 *   signature = "Collection findBigAccounts(double balanceGreaterThan)"
 *   ejb-ql = "SELECT OBJECT(h) FROM AccountEJB AS h WHERE balance > ?1"
 *
 * @ejbgen:relation
 *   name = Customer-Account
 *   target-ejb = CustomerEJB-OneToMany
 *   multiplicity = many
 *   cmr-field = customer
 *
 */
abstract public class AccountBean implements EntityBean {

  /**
   * @ejbgen:cmp-field column = acct_id
   * @ejbgen:primkey-field
   * @ejbgen:remote-method transaction-attribute = Required
   */
  abstract public String getAccountId();

  /**
   * @ejbgen:remote-method
   */
  abstract public void setAccountId(String val);
  // ....
}

As you can see from this example, there are two types of tags: class tags and method tags, depending on where you can use them.

Once you are done editing your file, you invoke EJBGen like this:

   java -classpath ejbgen.jar;%CLASSPATH% weblogic.tools.ejbgen.EJBGen AccountBean.java

When EJBGen exits, it will have generated the following files for you (and possibly more):

The rest of the procedure is standard EJB development:


Mailing-lists

There are two mailing-lists you can subscribe to if you are interested in EJBGen:

Installation

Unzip the package in, say, c:\ejbgen. Then

C:\> cd ejbgen
C:\ejbgen> java -classpath c:\ejbgen\ejbgen.jar;%CLASSPATH% weblogic.tools.EJBGen <your Java file>

Command line options

EJBGen supports the following options:

Command line Ant Property file Type Default Documentation
-checkTags checkTags ejbgen.checkTags [boolean]N/AIf invoked with this option, EJBGen will not generate any classe but will search the classes supplied on the command line for tags that are not valid EJBGen tags.
-classpath classPath sgen.classPath [classpath]N/AClass path.
-d outputDir sgen.outputDir [directory]N/AName of the directory where the files will be generated.
-descriptorDir descriptorDir ejbgen.descriptorDir [directory]N/AThe directory under which all the descriptor files will be created.
-docTag docTag ejbgen.docTag [string (name of the tag)]N/ADisplay the documentation for one tag
-docTags docTags ejbgen.docTags [boolean]N/APrint out all the tags known by EJBGen. Note that even though this option does not need any source file, you still need to specify an existing .java class on the command line, or Javadoc will emit an error message even though it recognized the flag.
-docTagsHtml docTagsHtml ejbgen.docTagsHtml [boolean]N/ADisplay the HTML documentation for one tag.
-ejbPrefix ejbPrefix ejbgen.ejbPrefix [string]noneThe prefix to use when generating the EJB class.
-ejbSuffix ejbSuffix ejbgen.ejbSuffix [string]EJB,BeanThe suffix to use when generating the EJB class.
-ejbgenQuiet ejbgenQuiet ejbgen.quiet [boolean]N/AMake EJBGen less verbose.
-ejbgenVerbose ejbgenVerbose ejbgen.ejbgenVerbose [boolean]N/AVerbose mode.
-errorFile errorFile ejbgen.errorFile [file]N/AThe path of the file where errors will be redirected.
-exitOnError exitOnError ejbgen.exitOnError [boolean]N/AEJBGen should exit in case of an error.
-experimental experimental ejbgen.experimental [boolean]N/AEnable experimental features.
-extractTemplates extractTemplates ejbgen.extractTemplates [directory]N/AThe directory where to extract the templates.
-forceGeneration forceGeneration ejbgen.forceGeneration [boolean]N/AForce the generation of all files regardless of time stamps.
-help help ejbgen.help [boolean]N/ADisplay the help.
-help help sgen.help N/ADisplays the help.
-homeBaseClass homeBaseClass home.baseClass [string (className)]N/AThe base class for home remote interfaces.
-ignorePackage ignorePackage ejbgen.ignorePackage [boolean]N/AIf this flag is set, EJBGen will ignore the package name of the Java files it generates and will create those in the output directory as specified by the -d flag (or in the current directory if no -d was specified).
-jndiPrefix jndiPrefix ejbgen.jndiPrefix [string]noneThe prefix to use for @remote-jndi-name and @local-jndi-name.
-jndiSuffix jndiSuffix ejbgen.jndiSuffix [string]noneThe suffix to use for @remote-jndi-name and @local-jndi-name
-localBaseClass localBaseClass local.baseClass [string (className)]N/AThe base class for local interfaces.
-localHomeBaseClass localHomeBaseClass localHome.baseClass [className]N/AThe base class for local home interfaces.
-localHomePrefix localHomePrefix ejbgen.localHomePrefix [string]noneThe prefix to use when generating the local EJB class.
-localHomeSuffix localHomeSuffix ejbgen.localHomeSuffix [string]LocalHomeThe suffix to use when generating the local EJB class.
-localPrefix localPrefix ejbgen.localPrefix [string]noneThe prefix to use when generating the local EJB class.
-localSuffix localSuffix ejbgen.localSuffix [string]LocalThe suffix to use when generating the local EJB class.
-noImports noImports ejbgen.noImports [boolean]falseDisable propagation of java imports to generated classes.
-noLocalInterfaces noLocalInterfaces ejbgen.noLocalInterfaces [boolean]N/AWhether local interfaces should be generated
-noRedirection noRedirection ejbgen.noRedirection [boolean]N/ACancel all redirection performed by EJBGen
-noRemoteInterfaces noRemoteInterfaces ejbgen.noRemoteInterfaces [boolean]N/AWhether remote interfaces should be generated.
-noValueClasses noValueClasses ejbgen.noValueClasses [boolean]N/AWhether value classes should be generated.
-noticeFile noticeFile ejbgen.errorNotice [file]N/AThe path of the file where notices will be redirected.
-pfd1 pfd1 ejbgen.pfd1 [boolean]N/AWhether EJBGen will generate deployment descriptors compatible with the Public Final Draft 1 of the EJB 2.0 specification. You should use this flag if you are using any version anterior to Weblogic 6.1.
-pfd2 pfd2 ejbgen.pfd2 [boolean]N/AWhether EJBGen will generate deployment descriptors compatible with the Public Final Draft 2 of the EJB 2.0 specification. You should use this flag if you are using any version anterior to Weblogic 6.1.
-primaryKeyBaseClass primaryKeyBaseClass primaryKey.baseClass [string (class name)]N/AThe base class for generated primary keys.
-printDiagnostic printDiagnostic ejbgen.printDiagnostic [boolean]N/APrints a diagnostic of all the tags found by EJBGen.
-printTags printTags ejbgen.printTags [boolean]N/ADisplay all the tags recognized by EJBGen.
-propertyFile propertyFile sgen.propertyFile [file]N/AName of the property file.
-remoteBaseClass remoteBaseClass remote.baseClass [string (className)]N/AThe base class for remote interfaces.
-remoteHomePrefix remoteHomePrefix ejbgen.remoteHomePrefix [string]noneThe suffix to use when generating the remote home EJB classes.
-remoteHomeSuffix remoteHomeSuffix ejbgen.remoteHomeSuffix [string]HomeThe suffix to use when generating the remote home EJB classes.
-remotePrefix remotePrefix ejbgen.remotePrefix [string]noneThe prefix to use when generating the remote EJB home class.
-remoteSuffix remoteSuffix ejbgen.remoteSuffix [string]noneThe suffix to use when generating the remote EJB home class.
-source source sgen.source [version number]1.3Version of the JDK to use.
-sourcepath sourcePath sgen.sourcePath [directory]N/ASource path.
-templateDir templateDir ejbgen.templateDir [directory]N/AThe directory where the templates are stored.
-toStringForPrimitivesOnly toStringForPrimitivesOnly ejbgen.toStringForPrimitivesOnly [boolean]N/AtoString() on value classes will only include primitive types.
-valueBaseClass valueBaseClass value.baseClass [string (class name)]N/AThe suffix to use when generating the value object class.
-valueObjectPrefix valueObjectPrefix ejbgen.valueObjectPrefix [string]noneThe prefix to use when generating the value object class.
-valueObjectSuffix valueObjectSuffix ejbgen.valueObjectSuffix [string]ValueThe suffix to use when generating the value object class.
-valuePackage valuePackage value.package [string (package name)]N/APackage the value classes belong to.
-verbose verbose sgen.verbose [boolean]falseDisplay more information.
-warningFile warningFile ejbgen.warningFile [file]N/AThe path of the file where warnings will be redirected.
-wls6 wls6 ejbgen.wls6 [boolean]N/AGenerate WebLogic 6.0 descriptors
-wls7 wls7 ejbgen.wls7 [boolean]N/AGenerate WebLogic 7.0 descriptors
-wls71 wls71 ejbgen.wls71 [boolean]N/AGenerate WebLogic 7.1 descriptors
-wls81 wls81 ejbgen.wls81 [boolean]N/AGenerate WebLogic 8.1 descriptors
-wls9 wls9 ejbgen.wls9 [boolean]N/AGenerate WebLogic 9 descriptors
-workshopDocTags workshopDocTags ejbgen.workshopDocTags [boolean]N/ADisplay the help in Workshop HTML format.
-xmlEncoding xmlEncoding ejbgen.xmlEncoding [string]N/AThe encoding to use when generating XML files (default: UTF-8).

Note that each option can be specified in three different ways:

Examples:

java -classpath c:\ejbgen\ejbgen.jar;%CLASSPATH% weblogic.tools.ejbgen.EJBGen -d foo -valueObjectSuffix DTO AccountBean.java 
Note: for the prefix/suffix options, use "none" if you want to use an empty string:
java -classpath c:\ejbgen\ejbgen.jar;%CLASSPATH% weblogic.tools.ejbgen.EJBGen
  -valueObjectSuffix none -valueObjectPrefix DTO AccountBean.java 



ANT Task

EJBGen contains an ant task which you can use in build build.xml file. The main class is com.bea.wls.ejbgen.ant.EJBGenAntTask and it can be used like this:

  <taskdef name="ejbgen" classname="com.bea.wls.ejbgen.ant.EJBGenAntTask" />

  <target name="build">
    <ejbgen
      outputDir = "gen"
      forceGeneration = "yes"
    >
      <classpath>
        <pathelement location="ejbgen.jar" />
      </classpath>
      <fileset dir="d:\t" includes="AccountEJB.ejb" />
    </ejbgen>
  </target>

This task supports the "fork" attributes and also the nested elements <fileset> and <classpath>. I strongly recommend to always invoke it with 'fork="yes"' or you might observe strange behaviors if the same JVM is used to run several EJBGen instances in a row. Another possible symptom that you should use the fork attribute is an OutOfMemoryException during your build.

Tags Documentation

@ejbgen:automatic-key-generation
Where:Class
Applicable on: Entity

Attribute Description Required
type (Oracle|SQLServer|SQLServer2000|NamedSequenceTable) Specifies the type of the key generator. Yes
cache-size Specifies the size of the key cache. No
name Names the key generator. No


@ejbgen:cmp-field
Where:Method
Applicable on: Entity

Attribute Description Required
column Specifies the column where this CMP field will be mapped. Yes
column-type (OracleClob|OracleBlob) Specifies the type of this column. No
exclude-from-value-object (True|False) If True, this field will not be generated in the value object. No
group-names Specifies the names of the groups to which this field belongs, separated by commas. No
ordering-number (0..n) Specifies the number where this field must appear in signatures and constructors. For this ordering to work, all CMR and CMP fields must have this attribute with a distinct numeric value. No
primkey-field (True|False) Sets whether this field is part of the compound primary key. No
read-only-in-value-object (True|False) If True, only the getter will be generated for this field in the value object. No
table-name Specifies the table(s) where this field should be mapped. No


@ejbgen:cmr-field
Where:Method
Applicable on: Entity

Attribute Description Required
exclude-from-value-object (True|False) If True, this field will not be generated in the value object. No
group-names Specifies the names of the groups to which this field belongs, separated by commas. No
ordering-number (0..n) Specifies the number where this field must appear in signatures and constructors. For this ordering to work, all CMR and CMP fields must have this attribute with a distinct numeric value. No
read-only-in-value-object (True|False) If True, only the getter will be generated for this field in the value object. No


@ejbgen:compatibility
Where:Class
Applicable on:All

Attribute Description Required
serialize-byte-array-to-oracle-blob (True|False) Whether a cmp-field of type byte[] mappedto a OracleBlob should be serialized No


@ejbgen:create-default-dbms-tables
Where:Class
Applicable on: Entity

Attribute Description Required
value This tag is deprecated; please use @ejbgen:jar-settings. No


@ejbgen:ejb-client-jar
Where:Class
Applicable on:All

Attribute Description Required
file-name This tag is deprecated; please use @ejbgen:jar-settings. Yes


@ejbgen:ejb-interface
Where:Class
Applicable on:All

Attribute Description Required
ejb-type (javax.ejb.MessageDrivenBean|javax.ejb.EntityBean|javax.ejb.SessionBean) Specifies the type of this EJB. This tag is not normally used. Yes


@ejbgen:ejb-local-ref
Where:Class
Applicable on:All

Attribute Description Required
home Names the Home class of the bean. No
id The identity of this tag (used for tag inheritance only). No
jndi-name Specifies the JNDI name of the reference. No
link Names the link of the bean. No
local Names the Local class of the bean. No
name Names the reference. No
type (Entity|Session) Specifies the reference type. No


@ejbgen:ejb-ref
Where:Class
Applicable on:All

Attribute Description Required
home Specifies the Home class of the bean. No
id The identity of this tag (used for tag inheritance only). No
jndi-name Specifies the JNDI name of the reference. No
link Specifies the link of the bean. No
name Names the reference. No
remote Specifies the Remote class of the bean. No
type (Entity|Session) Specifies the type of the reference. No


@ejbgen:entity
Where:Class
Applicable on: Entity

Attribute Description Required
ejb-name Names this Entity bean. Yes
prim-key-class Names the Java class of the primary key. In case of a compound primary key, this class will be generated by EJBGen. Yes
abstract-schema-name Gives the abstract schema name for this EJB. If not specified, the ejb-name value will be used. No
cache-between-transactions (True|False) Specifies whether to cache the persistent data of an entity bean across (between) transactions. No
check-exists-on-method (True|False) Specifies whether the container checks for the existence of a bean for each method call. No
clients-on-same-server (True|False) Specifies whether the clients are colocated with the EJB on the same server. No
concurrency-strategy (ReadOnly|Exclusive|Database|Optimistic) Defines the concurrency strategy for this bean. No
data-source-name Names the DataSource declared in config.xml. No
database-type (DB2|Informix|Oracle|SQLServer|Sybase|PointBase|SQLServer2000) Specifies the database type of the underlying DBMS. No
db-is-shared (True|False) No
default-dbms-tables-ddl Specifies the DDL file name. No
default-transaction (NotSupported|Supports|Required|RequiresNew|Mandatory|Never) Sets the default transaction attribute to be applied to all methods that do not have a transaction attribute setting. No
delay-database-insert-until (ejbCreate|ejbPostCreate) No
delay-updates-until-end-of-tx (True|False) Determines whether updates will be sent after the transaction has been committed. No
disable-warning Deprecated, use @ejbgen:jar-settings No
dispatch-policy Specifies the dispatch policy queue for this bean. No
enable-batch-operations (True|False) Determines whether to perform batch operations. No
enable-call-by-reference (True|False) Specifies whether the container will call this EJB by reference. No
enable-dynamic-queries (True|False) Specifies whether dynamic queries are enabled. No
finders-load-bean (True|False) If set to True, the beans will immediately be loaded into the cache by the finder. No
home-call-router-class-name Names the class to be used for routing home method calls. No
home-is-clusterable (True|False) Determines whether this bean can be deployed from multiple servers in a cluster. No
home-load-algorithm (RoundRobin|Random|WeightBased|RoundRobinAffinity|RandomAffinity|WeightBasedAffinity) Specifies the algorithm to use for load-balancing between replicas of this home. No
idle-timeout-seconds Sets the maximum duration an EJB should stay in the cache, in seconds. No
initial-beans-in-free-pool Specifies the initial number of beans in the free pool. No
instance-lock-order (AccessOrder|ValueOrder) The locking order for this Entity bean. No
invalidation-target Targets the ejb-name of a read-only Entity bean to be invalidated when this Container-Managed Persistence Entity EJB is modified. No
lock-order Sets the database locking order of this bean when a transaction involves multiple beans. No
max-beans-in-cache Sets the maximum number of beans in cache. No
max-beans-in-free-pool Specifies the maximum number of beans in the free pool. No
optimistic-column Specifies the column that holds the timestamp for optimistic concurrency. No
order-database-operations (True|False) Determines whether to sort the database operations. No
prim-key-class-nogen (True|False) If this keyword is specified, EJBGen will not generate the primary key class (it is assumed that you are providing it). No
read-timeout-seconds Sets the number of seconds between each ejbLoad() call on a read-only Entity bean. No
reentrant (True|False) No
run-as Specifies the role-name for this EJB. No
run-as-identity-principal Gives the name of the principal in case the role maps to several principals. No
table-name Names the table to which this Entity bean is mapped. No
trans-timeout-seconds Sets the transaction timeout (in seconds). No
use-caller-identity (True|False) Determines whether or not this EJB uses the callers identity. No
use-select-for-update (True|False) If true, causes SELECT ... FOR UPDATE to be used whenever the bean is loaded from the database. No
validate-db-schema-with (MetaData|TableQuery) Specifies the method used to validate the tables created by the EJB container. No
verify-columns (Read|Modified|Version|Timestamp) Specifies how optimistic concurrency verifies that the columns have or have not been modified during transactions. No
verify-rows (Read|Modified) Specifies the rows in a table that should be checked when optimistic concurrency is used. No


@ejbgen:entity-cache-ref
Where:Class
Applicable on: Entity

Attribute Description Required
concurrency-strategy (ReadOnly|Exclusive|Database) Defines the concurrency strategy for this bean. Yes
name Names the cache. Yes
cache-between-transactions (True|False) Sets whether to cache the persistent data of an entity bean across (between) transactions. No
estimated-bean-size Specifies the estimated average size of the instances of an entity bean, in bytes. No


@ejbgen:env-entry
Where:Class
Applicable on:All

Attribute Description Required
name Names this environment entry. Yes
type (java.lang.Boolean|java.lang.String|java.lang.Character|java.lang.Integer|java.lang.Double|java.lang.Byte|java.lang.Short|java.lang.Long|java.lang.Float) Specifies the Java type for this environment entry (must be fully qualified, even if the type is java.lang). Yes
value Specifies the value for this environment entry. Yes


@ejbgen:file-generation
Where:Class
Applicable on:All

Attribute Description Required
local-class (True|False) Whether to generate the local interface for this EJB. No
local-class-name The name of the local class to be generated. No
local-home (True|False) Whether to generate the local home interface for this EJB. No
local-home-name The name of the local home class to be generated. No
local-home-package The package for the local home interface. No
local-package The package for the local interface. No
pk-class (True|False) Whether to generate the primary key class for this EJB. No
remote-class (True|False) Whether to generate the remote interface for this EJB. No
remote-class-name The name of the remote class to be generated. No
remote-home (True|False) Whether to generate the remote home interface for this EJB. No
remote-home-name The name of the remote home class to be generated. No
remote-home-package The package for the remote home interface. No
remote-package The package for the remote interface. No
value-class (True|False) Whether to generate the value class for this EJB. No
value-class-name The name of the value class to be generated. No


@ejbgen:finder
Where:Class
Applicable on: Entity

Attribute Description Required
caching-name Specifies the name of an eager relationship caching. No
comment Defines a comment that will be reproduced above the generated finder Java method. No
ejb-ql Specifies the EJB QL request as it will appear in the deployment descriptor. No
generate-on (Local|Remote) Determines which Home this finder will be generated on. If unspecified, it will be generated on both. No
group-name Names the group for the WebLogic Server query. No
id The identity of this tag (used for tag inheritance only). No
include-updates (True|False) Determines whether updates made during the current transaction must be reflected in the result of a query. No
isolation-level (TransactionSerializable|TransactionReadCommitted|TransactionReadUncommitted|TransactionRepeatableRead) Specifies the type of transaction isolation for this method. No
max-elements Specifies the maximum number of elements that should be returned by a multi-valued query. No
signature Specifies exactly the signature to be generated on the Home class. EJBGen will add the conformant exceptions, but you must specify the fully qualified type of each parameter, even if it belongs to java.lang. No
sql-select-distinct (True|False) Determines whether the generated SQL SELECT will contain a DISTINCT qualifier. No
transaction-attribute (NotSupported|Supports|Required|RequiresNew|Mandatory|Never) Specifies the transaction attribute for this local method. If not specified, the default transaction attribute will be used. Methods with this tag will be generated on the Local class. No
weblogic-ejb-ql Specifies the Weblogic Server EJB QL request as it will appear in the deployment descriptor. Note: if this request is needed, enclose both EJB-QL and Weblogic Server EJB-QL within double quotes. No


@ejbgen:foreign-jms-provider
Where:Class
Applicable on: Message-Driven

Attribute Description Required
connection-factory-jndi-name Specifies the connection factory JNDI name. No
initial-context-factory Specifies the initial JNDI context factory. No
provider-url Specifies the provider URL. No


@ejbgen:jar-settings
Where:Class
Applicable on:All

Attribute Description Required
create-tables Whether to create tables. No
disable-warning A comma-separated line of warnings to disable when running ejbc. No
ejb-client-jar Specifies the name of the client JAR to be generated. If multiple EJBs have this tag, only one of the specified JAR files will be included in the deployment descriptor. No
enable-bean-class-redeploy (True|False) Determines whether this EJB can be redeployed without redeploying the entire module. No


@ejbgen:jndi-name
Where:Class
Applicable on:All

Attribute Description Required
local Specifies the local JNDI name of this EJB. If a local JNDI name is not specified, no local interfaces will be generated. No
remote Specifies the remote JNDI name of this EJB. If a remote JNDI name is not specified, no remote interfaces will be generated. No


@ejbgen:local-home-method
Where:Method
Applicable on: Entity Session

Attribute Description Required
is-idempotent (True|False) Sets whether this method is idempotent. No
isolation-level (TransactionSerializable|TransactionReadCommitted|TransactionReadUncommitted|TransactionRepeatableRead) Specifies the type of transaction isolation for this method. No
ordering-number (0..n) Specifies the number where this method must appear in the generated class. No
roles Defines a comma-separated list of roles that are allowed to invoke this method. No
transaction-attribute (NotSupported|Supports|Required|RequiresNew|Mandatory|Never) Specifies the transaction attribute for this local method. If not specified, the default transaction attribute will be used. Methods with this tag will be generated on the Local class. No


@ejbgen:local-method
Where:Method
Applicable on: Entity Session

Attribute Description Required
is-idempotent (True|False) Specifies whether this method is idempotent. No
isolation-level (TransactionSerializable|TransactionReadCommitted|TransactionReadUncommitted|TransactionRepeatableRead) Specifies the type of transaction isolation for this method. No
ordering-number (0..n) Specifies the number where this method must appear in the generated class. No
roles Defines a comma-separated list of roles that are allowed to invoke this method. No
transaction-attribute (NotSupported|Supports|Required|RequiresNew|Mandatory|Never) Specifies the transaction attribute for this local method. If not specified, the default transaction attribute will be used. Methods with this tag will be generated on the Local class. No


@ejbgen:message-driven
Where:Class
Applicable on: Message-Driven

Attribute Description Required
destination-jndi-name Gives the JNDI name of the destination of this Message-Driven bean. Yes
destination-type (javax.jms.Queue|javax.jms.Topic) Specifies the destination type of the Message-Driven bean. Yes
ejb-name Specifies the name of this Message-Driven bean. Yes
acknowledge-mode (auto-acknowledge|dups-ok-acknowledge) Specifies the acknowledgement mode of this Message-Driven bean. No
clients-on-same-server (True|False) Specifies whether the clients are colocated with the EJB on the same server. No
create-as-principal-name Names the principal to be used when ejbCreate would otherwise run with an anonymous principal. No
default-transaction (NotSupported|Required) Specifies the transaction attribute to be applied to all methods that do not have a specific transaction attribute setting. No
dispatch-policy Specifies the dispatch policy queue for this bean. No
durable (True|False) If the destination-type is Topic, setting this attribute to True will make the subscription durable. No
initial-beans-in-free-pool Specifies the initial number of beans in the free pool. No
jms-client-id The client id of this EJB. No
jms-polling-interval-seconds The number of seconds between each attempt to reconnect to the JMS destination. No
max-beans-in-free-pool Specifies the maximum number of beans in the free pool. No
message-selector Specifies the JMS message selector of this Message-Driven bean. No
passivate-as-principal-name Names the principal to be used when ejbPassivate would otherwise run with an anonymous principal. No
remove-as-principal-name Names the principal to be used when ejbRemove would otherwise run with an anonymous principal. No
run-as Specifies the role-name for this EJB. No
run-as-identity-principal Specifies the name of the principal in case the role maps to several principals. No
trans-timeout-seconds Specifies the transaction timeout (in seconds). No
transaction-type (Bean|Container) Specifies where the transactions for this EJB are managed. No
use-caller-identity (True|False) Specifies whether this EJB uses callers identity. No


@ejbgen:method-isolation-level-pattern
Where:Class
Applicable on:All

Attribute Description Required
isolation-level (TransactionSerializable|TransactionReadCommitted|TransactionReadUncommitted|TransactionRepeatableRead) Specifies the isolation level for the methods specified in the pattern tag. Yes
pattern Specifies the pattern that matches all methods that will receive this isolation level (e.g. "*"). Yes
id The identity of this tag (used for tag inheritance only). No


@ejbgen:method-permission-pattern
Where:Class
Applicable on:All

Attribute Description Required
pattern Specifies the pattern that matches all methods that will receive this method permission (e.g. "*"). Yes
roles Specifies the roles for the methods specified in the pattern tag, separated by a comma. Yes
id The identity of this tag (used for tag inheritance only). No
interface (Home|Remote|LocalHome|Local) Specifies the interface to which this permission pattern applies. No
itf (Home|Remote|LocalHome|Local) Specifies the interface to which this permission pattern applies. No


@ejbgen:relation
Where:Class
Applicable on: Entity

Attribute Description Required
multiplicity (one|many) Sets the multiplicity of the relationship. Yes
name Specifies the name of the relationship. Use the same name on both ends of a relationship (note that this constraint applies to unidirectional relationships as well). Yes
cascade-delete (True|False) No
cmr-field Specifies the CMR field where this relationship will be kept. This field is optional. If it not present, the relationship is unidirectional. If it is present, the attribute fk-column must be specified as well. No
db-cascade-delete (True|False) Determines whether a cascade delete will use the built-in cascade delete facilities of the underlying DBMS. No
fk-column Needed only in a relationship having at least one One side. The non-One side EJB must declare the column that it will use to store the primary key of its counterpart. No
foreign-key-table The name of a DBMS table that contains a foreign-key. No
id The identity of this tag (used for tag inheritance only). No
joint-table Only needed in a Many-Many relationship. Must be the name of an existing table that will be used to hold the joint table containing the relationships. If you are using a compound primary key, specify a set of corresponding foreign keys separated by a comma. No
primary-key-table The name of a DBMS table that contains a primary-key. No
role-name The name of this role (such as "ParentHasChildren"). If no role name is given, EJBGen will generate one for you. You must specify a role-name in order to inherit relations. No
target-ejb Specifies the EJB name of the target of this relationship, which is used to generate the role name. If not supplied, a unique string will be generated. No


@ejbgen:relationship-caching-element
Where:Class
Applicable on: Entity

Attribute Description Required
caching-name Specifies the name of an eager relationship caching. Yes
cmr-field Provides a comma-separated list of CMR field names. Yes
group-name Specifies the name of the group to be loaded for the CMR field. No
id The identity of this tag (used for tag inheritance only). No
parent-id Specifies the parent ID of this element. No


@ejbgen:remote-home-method
Where:Method
Applicable on: Entity Session

Attribute Description Required
is-idempotent (True|False) Specifies whether this method is idempotent. No
isolation-level (TransactionSerializable|TransactionReadCommitted|TransactionReadUncommitted|TransactionRepeatableRead) Specifies the type of transaction isolation for this method. No
ordering-number (0..n) Specifies the number where this method must appear in the generated class. No
roles Specifies a comma-separated list of roles that are allowed to invoke this method. No
transaction-attribute (NotSupported|Supports|Required|RequiresNew|Mandatory|Never) Specifies the transaction attribute for this remote method. If not specified, the default transaction attribute will be used. Methods with this tag will be generated on the Remote class. No


@ejbgen:remote-method
Where:Method
Applicable on: Entity Session

Attribute Description Required
is-idempotent (True|False) Determines whether this method is idempotent. No
isolation-level (TransactionSerializable|TransactionReadCommitted|TransactionReadUncommitted|TransactionRepeatableRead) Specifies the type of transaction isolation for this method. No
ordering-number (0..n) Specifies the number where this method must appear in the generated class. No
roles Defines a comma-separated list of roles that are allowed to invoke this method. No
transaction-attribute (NotSupported|Supports|Required|RequiresNew|Mandatory|Never) Specifies the transaction attribute for this remote method. If not specified, the default transaction attribute will be used. Methods with this tag will be generated on the Remote class. No


@ejbgen:resource-env-ref
Where:Class
Applicable on:All

Attribute Description Required
name Names the resource environment reference. Yes
type Specifies the type of the environment resource references (e.g., javax.jms.Queue). Yes
id The identity of this tag (used for tag inheritance only). No
jndi-name Gives the JNDI name of the resource. No


@ejbgen:resource-ref
Where:Class
Applicable on:All

Attribute Description Required
auth (Application|Container) Yes
jndi-name Specifies the JNDI name of the resource. Yes
name Names the resource. Yes
type Specifies the type of the resource (e.g., javax.sql.DataSource). Yes
id The identity of this tag (used for tag inheritance only). No
sharing-scope (Shareable|Unshareable) No


@ejbgen:role-mapping
Where:Class
Applicable on:All

Attribute Description Required
role-name Specifies the name of the role. Yes
externally-defined (True|False) Trus if this role is defined externally. No
global-role (True|False) True if this role is global. No
id The identity of this tag (used for tag inheritance only). No
principals Specifies the names of the principals in this role (separated by commas). No


@ejbgen:security-role-ref
Where:Class
Applicable on: Entity Session

Attribute Description Required
role-name Specifies the name of the security role. Yes
id The identity of this tag (used for tag inheritance only). No
role-link References a defined security role. No


@ejbgen:select
Where:Method
Applicable on: Entity

Attribute Description Required
caching-name Specifies the name of an eager relationship caching. No
ejb-ql Specifies the EJB-QL that defines this select method. The method name must start with ejbSelect. No
group-name Names the group for the WebLogic Server query. No
include-updates (True|False) Determines whether updates made during the current transaction must be reflected in the result of a query. No
max-elements Specifies the maximum number of elements that should be returned by a multi-valued query. No
ordering-number (0..n) Specifies the number where this method must appear in the generated class. No
result-type-mapping (Remote|Local) Specifies whether the returned objects are mapped to EJBLocalObject or EJBObject. No
sql-select-distinct (True|False) Determines whether the generated SQL SELECT will contain a DISTINCT qualifier. No
weblogic-ejb-ql Specifies the Weblogic Server EJB-QL request as it will appear in the deployment descriptor. Note: if this request is needed, enclose both EJB-QL and Weblogic Server EJB-QL within double quotes. No


@ejbgen:service-ref
Where:Class
Applicable on:All

Attribute Description Required
name Name of this service in the WSDL fi. Yes
wsdl-uri Location of the WSDL file. Yes
handler-chain-uri The location of the XML file that contains the handler chain information. No
jaxrpc-mapping-file Name of the jax-rpc mapping file. If not provided, clientgen will choose a name. No
package-name Package name for the clientgen generated classes/interfaces. No


@ejbgen:session
Where:Class
Applicable on: Session

Attribute Description Required
ejb-name Names this Session bean. Yes
allow-concurrent-calls (True|False) Specifies whether to allow concurrent calls on that EJB. No
allow-remove-during-transaction (True|False) Specifies whether remove() can be invoked during a transaction. No
bean-load-algorithm Specifies the algorithm to be used for load-balancing among replicas of this bean. No
cache-type (NRU|LRU) Specifies the type of the cache for this stateful Session bean. No
call-router-class-name Gives class name to be used for routing home method calls. No
clients-on-same-server (True|False) Specifies whether the clients are colocated with the EJB on the same server. No
create-as-principal-name Names the principal to be used when ejbCreate would otherwise run with an anonymous principal. No
default-transaction (NotSupported|Supports|Required|RequiresNew|Mandatory|Never) Specifies the transaction attribute to be applied to all methods that do not have a specific transaction attribute setting. No
dispatch-policy Specifies the dispatch policy queue for this bean. No
enable-call-by-reference (True|False) Specifies whether the container will call this EJB by reference. No
home-call-router-class-name Names class to be used for routing home method calls. No
home-is-clusterable (True|False) Specifies whether this bean can be deployed from multiple servers in a cluster. No
home-load-algorithm (RoundRobin|Random|WeightBased|RoundRobinAffinity|RandomAffinity|WeightBasedAffinity) Specifies the algorithm to use for load-balancing between replicas of this home. No
idle-timeout-seconds Specifies the maximum duration an EJB remains cached. No
initial-beans-in-free-pool Specifies the initial number of beans in the free pool. No
is-clusterable (True|False) Sets whether this bean is clusterable. No
max-beans-in-cache Specifies the maximum number of beans in the cache. No
max-beans-in-free-pool Specifies the maximum number of beans in the free pool. No
methods-are-idempotent (True|False) Specifies whether the methods for this stateless session bean are idempotent or not. No
passivate-as-principal-name Names the principal to be used when ejbPassivate would otherwise run with an anonymous principal. No
persistent-store-dir Specifies the directory in which to store the passivated beans. No
remove-as-principal-name Names the principal to be used when ejbRemove would otherwise run with an anonymous principal. No
replication-type (InMemory|None) Specifies how to replicate stateful session beans in a cluster. No
run-as Specifies the role-name for this EJB. No
run-as-identity-principal Specifies the name of the principal when the role maps to several principals. No
service-endpoint The fully-qualified name of the enterprise beans web service endpoint interface. No
session-timeout-seconds Specifies the number of seconds an EJB stays alive before being passivated. No
trans-timeout-seconds Specifies the transaction timeout (in seconds). No
transaction-type (Bean|Container) Specifies who manages the transactions for this EJB. No
type (Stateless|Stateful) Specifies the type of the Session bean. If this attribute is not specified, EJBGen will guess the right type by looking at the ejbCreate() methods on your class. No
use-caller-identity (True|False) Specifies whether this EJB uses callers identity. No


@ejbgen:value-object
Where:Class
Applicable on:All

Attribute Description Required
reference (Local|Value) Specifies what objects the value object class should reference when accessing other EJBs. No


[JAM] Warning: failed to resolve class javax.ejb.CreateException [JAM] Warning: failed to resolve class javax.ejb.EntityBean [JAM] Warning: failed to resolve class javax.ejb.EntityContext [JAM] Warning: failed to resolve class javax.ejb.RemoveException [JAM] Warning: failed to resolve class CreateException Warning: [PortalStudio_Group] Found unqualified primary key class 'Long', assuming you mean java.lang.Long. Exception in thread "main" com.bea.wls.ejbgen.EJBGenException: Error: [PortalStudio_Group] [ejb-ref name=ref link=PortalStudio_GroupMembership] must have either 'link' or all of 'name', 'type', 'home', 'remote|local' attributes specified. at com.bea.wls.ejbgen.Utils.error(Utils.java:127) at com.bea.wls.ejbgen.Utils.error(Utils.java:96) at com.bea.wls.ejbgen.EJBGenCommon.completeEJBRefs(EJBGenCommon.java:123) at com.bea.wls.ejbgen.EJBGenCommon.completeEJBRemoteRefs(EJBGenCommon.java:38) at com.bea.wls.ejbgen.EJBGenCommon.completeBeanInformation(EJBGenCommon.java:32) at com.bea.wls.ejbgen.EJBGenSGen.initModule(EJBGenSGen.java:110) at com.bea.sgen.SGen.run(SGen.java:199) at com.bea.wls.ejbgen.EJBGen.main(EJBGen.java:303) at com.bea.wls.ejbgen.EJBGen.main(EJBGen.java:311) at weblogic.tools.ejbgen.EJBGen.main(EJBGen.java:21)

Controlling the generation of files

The Java sources generated by EJBGen can be controlled by the tag @ejbgen:file-generation. In the absence of this tag, EJBGen will generate the following files:

You can selectively disable the generation of these files by using the @ejbgen:file-generation tag. This can be done on a per-bean basis. For example, if you are not interested in the generation of value classes for a bean:


/**
 * @ejbgen:file-generation
 *   value-class = False
 */

Note that if you specify -noValueClasses, -noRemoteInterfaces or -noLocalInterfaces, these command-line switches override any tag found on the beans. Also, this tag has no impact on the deployment descriptors. What decides if a bean is remote and/or local in the deployment descriptors is the presence of the @ejbgen:jndi-name tag.

Templates

EJBGen uses predefined templates to generate files. If the generated files do not fit your needs, you can override those templates in order to add what you need. Here are the steps to accomplish this:

Also, all the variables defined in your property file (as specified with -propertyFile) are made available to the templates. For example, you can define the following property in ejbgen.properties:

my-method = public void myMethod();

and then use a reference to this variable in one of your Java templates:

public interface $remoteHomeClassName $implements {
  $my-method

  // ...

Property files and substitution variables

Property File

You can ask EJBGen to parse a Properties File with the -propertyFile option. The file can look like this:

#
# property-file
#
remote-jndi-name = Account

You need to invoke ejbgen with the -propertyFile switch:

   java -classpath ejbgen.jar;%CLASSPATH% weblogic.tools.ejbgen.EJBGen -propertyFile property-file AccountBean.java

EJBGen recognizes two kinds of variables in this file: user variables and predefined variables.

User Variables

EJBGen tags can use variables instead of strings. These variables must be enclosed with "${" and "}". For example:

  @ejbgen:jndi-name
     remote = ${remote-jndi-name}
Variables can be used anywhere after an EJBGen tag, so they can contain whole tag definitions:

@ejbgen:jndi-name
  ${jndi-name-tag}
#
# property-file
#
jndi-name-tag = remote = RemoteAccount local = LocalAccount
Predefined Variables

EJBGen recognizes a number of predefined variables. These variables are not supposed to be used in tags but EJBGen will use them at various places depending on their role. Here is the list of recognized variables:

Additionally, you can make these variables more specific by prefixing them with an EJBName. For example, consider the following property file:

#
# property-file
#
Account.home.baseClass = BaseAccountHome
home.baseClass = BaseHome
value.package = value
containerManaged.value.package=valuePackageForContainerManaged
All homes generated by EJBGen will extend the class BaseHome except the home of EJB "Account", which will extend BaseAccountHome.

Jar settings

The tag @ejbgen:jar-settings is a little bit different from the other tags since it contains settings that apply to all the EJB's. Since it is possible to define this tag in several source files, you might define settings the override each other. EJBGen will display a warning when this happens, but the best way to handle this scenario is to use a property file.

Generally, you should not use @ejbgen:jar-settings in a source file. You can provide the values for these attributes in the property file with the following syntax:

#
# property-file
#
ejbgen.jar-settings.create-tables = CreateOnly
ejbgen.jar-settings.ejb-client-jar = client.jar
ejbgen.jar-settings.enable-bean-class-redeploy = True

Relationships

Upgrading relationships to use local interfaces

If you have EJB's based on a version of the EJB 2.0 specification that predates PFD2, you will need to update them. As of PFD2, relationships must be based on local interfaces, not remote ones. Here are the steps you need to take up upgrade your EJB's:


Inheritance of tags

One of the main features in EJBGen 2.0 is the possibility to inherit tags. You can now inherit EJBGen annotations the same way you do it in Java. For example, assume that you have an EJB named AccountEJB with a base class BaseAccount:

/**
 * @ejbgen:jndi-name
 *     remote="BaseRemote"
 */
public class BaseAccount implements EntityBean {
  // ...
}
Now you define your EJB class:

/**
 * @ejbgen:entity
 *   ejb-name = containerManaged
 *   table-name = ejbAccounts
 *   data-source-name = examples-dataSource-demoPool
 *
 *  Note that we inherit the JNDI name defined in BaseAccount
 */
public class AccountEJB extends BaseAccount {
  // ...
You can also inherit attributes, not just tags. This is a very powerful feature with a lot of potential uses. For example, you could define a setting common to all your EJB's, such as max-beans-in-cache:

/**
 * @ejbgen:entity
 *    max-beans-in-cache = 300
 */
public class BaseAccount implements EntityBean {
  // ...
}
Then, you define your Entity bean as follows:

/**
 * @ejbgen:entity
 *   ejb-name = containerManaged
 *   table-name = ejbAccounts
 *   data-source-name = examples-dataSource-demoPool
 *
 *   // automatically inherit the attribute max-beans-in-cache = 300
 */
public class AccountEJB extends BaseAccount {
  // ...
Of course, you still have the ability to modify the inherited value. For example, if for a specific bean, you need to change the default value of max-beans-in-cache from 300 to 400:

/**
 * @ejbgen:entity
 *   ejb-name = containerManaged
 *   table-name = ejbAccounts
 *   data-source-name = examples-dataSource-demoPool
 *   max-beans-in-cache = 400
 *
 *   // the above setting overrides the one defined in the base class
 */
public class AccountEJB extends BaseAccount {
  // ...

A note on inheritance of relations and certain other tags

When you decide to use inheritance on tags that can appear more than once (such as @ejbgen:relation, or @ejbgen:env-entry), you need to specify an attribute called "id" in order for EJBGen to be able to resolve your inheritance hierarchy.

Here is an example of an inherited relation. The parent class first, which defines a partial relation (no cmr-field). Note the presence of the "id" attribute:

/**
 * @ejbgen:relation
 *   id = MyRelation
 *   name = Many1-Many2
 *   role-name = Many1HasMany2
 *   multiplicity = many
 *   role-name = Many1HasMany2
 *   target-ejb = Many2EJB
 *   fk-column = many2_fk
 *   joint-table = join_table
 */

abstract public class BaseMany1 extends BaseEntityBean {

And now the real EJB, which inherits the above relation tag, specifies a similar "id" attribute and completes the definition of the relation:

/**
 * @ejbgen:relation
 *   id = MyRelation
 *   cmr-field = many2
 *
 */
abstract public class Many1EJB extends BaseMany1 {
This restriction doesn't apply to tags that can appear at most once, such as @ejbgen:entity, because there is clearly no ambiguity when resolving the inheritance tree in that case.

Home Methods

In order to declare a Home Method on your bean, you need to tag it with @ejbgen:remote-home-method, @ejbgen:local-home-method or both. Also, your method must start with "ejbHome".

Notes:


ANT support

ANT is an alternative to make that allows you to build complex projects. EJBGen will generate a build file for ANT so that the generated EJB can be compiled and packaged easily.

By default, EJBGen will create a file called ejbgen-build.xml in the current directory (this name can be changed, see below). The typical sequence to build a fully functional EJB will therefore be:

$ java -classpath c:\ejbgen\ejbgen.jar;%CLASSPATH% weblogic.tools.ejbgen.EJBGen AccountBean.java CustomerBean.java
$ ant -buildfile ejbgen-build.xml
You can customize the generated file through several System Properties, enumerated below. For example, if you want to name the generated XML file "project.xml", you will invoke EJBGen this way:
$ java Dant.buildFileName=project.xml -classpath c:\ejbgen\ejbgen.jar;%CLASSPATH% weblogic.tools.ejbgen.EJBGen
  AccountBean.java CustomerBean.java
The supported properties, and their default value, are:

Stateful and Stateless Session Beans

EJBGen automatically detects the kind of Session Bean you are trying to deploy. It looks at your ejbCreate() methods and it finds at least one that has a non-empty list of parameters, it will generate a Stateful Session Bean. Otherwise, the bean will be Stateless.

Compound Primary Keys

Sometimes, a simple (e.g. java.lang.String) primary key class will not be enough to identify your EJB's uniquely. In such a case, you need to use a compound primary key, which is basically a custom Java class containing several fields. All these fields together define your EJB uniquely. There are certain constraints associated with the compound primary key class (e.g it must be Serializable, implement hashCode(), equals(), etc...) so EJBGen can generate it for you.

A compound primary key class must contain fields that form a subset of the CMP fields of your EJB. In order to define a compound primary key class with EJBGen, you need to do the following:

With this information, EJBGen will generate a compound primary key class for you with the following characteristics:

Please refer to the example in examples/ejb20/basic/compoundPK/ for an illustration of compound primary key generation.


EJB References

EJB References (either @ejbgen:ejb-ref or @ejbgen:ejb-local-ref) can be specified in two ways:

Note that as long as you have specified a value for link, you can set some other values as well. These will not be overridden:

 * @ejbgen:ejb-ref
 *   link = PortalStudio_Group     // must be the EJB name of another EJB
 *   name = MyName    // EJBGen will reuse this value and guess the missing ones
 *

Reverse EJBGen

EJBGen is shipped with a tool called Reverse EJBGen. This tool needs Weblogic 7.0 to run and it generates EJBGen classes from a .jar file.

Sample use:

c:\> java com.bea.wls.revejbgen.Main bands.jar
Creating BaseMusicLibraryBean.java
Creating BaseBandBean.java
Creating BaseFanClubBean.java
Creating BaseRecordingBean.java
Creating BaseArtistBean.java
Note that the generated classes are abstract base classes for your EJB's: you need to make your EJB's inherit from them in order for the EJBGen tags to be recognized.

Relationship caching

You can specify relationship caching elements with the tag @ejbgen:relationship-caching. This XML element has a particularity: it can be nested (recursive). In other words, you can specify a tree representing all the relationship elements that you want to see cached.

In order to support this tree structure, @ejbgen:relationship-caching has two attributes, id and parent-id. These attributes do not correspond to any XML, they simply allow you to specify your tree structure.

For example, if a caching-element A needs to have two children elements B and C, all you need to specify is an id for A (say "root0") and a parent-id for B and C equal to that name.

Here is an example of a specification:

 * @ejbgen:relationship-caching-element
 *   caching-name = cacheMoreBeans
 *   cmr-field = employee
 *   group-name = emp-group
 *   id = A
 * 
 * @ejbgen:relationship-caching-element
 *   caching-name = cacheMoreBeans
 *   cmr-field = employee_ssn
 *   group-name = emp-group
 *   parent-id = A
 * 
 * @ejbgen:relationship-caching-element
 *   caching-name = cacheMoreBeans
 *   cmr-field = employee_zip
 *   group-name = emp-group
 *   parent-id = A

Frequently Asked Questions

Q: Inheritance doesn't seem to work.

A: First of all, that's not a question. Second, JavaDoc is very capricious when it comes to locating source files. Here are a few suggestions to help you locate the problem:

Q: EJBGen is giving me the following error:

weblogic.tools.ejbgen.EJBGenException: [Office] Error:Role in relation office-addresses,
2 PK fields were declared but 1 foreign keys were found. Both numbers must be equal.


A: Make sure that you specified your list of foreign key columns in double quotes:
*   fk-column = "office_address, office_floor"

Q: What's the best way to design my EJB's using inheritance?

A: I recommend to use Java classes as base classes and not EJB's. For example, suppose you have AddressEJB and USAddressEJB, which should inherit from AddressEJB. Create a Java class BaseAddress.java that contains all the tags and methods that are common to AddressEJB and USAddressEJB. Then both EJB's extend this Java class and add their own specific tags and methods (ideally, AddressEJB would extend BaseAddress and not any tag of its own).

Q: How can I specify a "//" in a value? (e.g. provider-url = http://localhost:7001)?

A: Use double quotes: provider-url = "http://localhost:7001" (otherwise anything past // will be ignored, since it is legal to specify comments in EJBGen values).

Q: I specified

  * group-names = group1, group2
but EJBGen doesn't recognize group2.

A: You must use double quotes in all tags that have spaces in them. I recommend you do that for all tags anyway, since it will make your migration to JSR 175 easier:

  * group-names = "group1, group2"

Q: Several methods on my EJB are overloaded and declared as remote (or local) but they don't all appear in the generated remote (or local) home.

A: This is a bug in JavaDoc, which has been discussed on the mailing-list and filed with Sun as bugs 4957170 and 4836189. The only workaround right now is to add a dummy parameter to one of the overloaded methods.


Mapping an Entity bean to several tables

By default, Entity beans are mapped to one table, with the attribute table-name on the tag @ejbgen:entity. If you want to map your Entity bean to more than one table, you can use the table-name attribute on individual @ejbgen:cmp-fields. All the CMP fields that do not have a table-name attribute will use the table specified on @ejbgen:entity (which can therefore be considered as the "default" table).

If you want to map an Entity bean to several tables, you need to specify a comma-separated list of tables in the table-name attribute (and also on column). For example:

  /**
   * @ejbgen:cmp-field
   *   column = "bal1, bal2"
   *   table-name = "Table1, Table2"
   */
Make sure that the number of tables matches the number of columns, and that the columns exist in the corresponding table (for example, in the example above, Table1 must contain column bal1, and Table2, bal2).

findByPrimaryKey()

You can control attributes associated to findByPrimaryKey() (e.g. transaction-attribute, group-name, etc...) just like for any other finder. The only difference is that the container generates the implementation of findByPrimaryKey(), so the ejb-ql you specify will be ignored. You still need to specify something, though, since it is a required attribute of @ejbgen:finder.

For example:

 * @ejbgen:finder
 *   ejb-ql = "will be ignored"
 *   signature = "findByPrimaryKey()"
 *   transaction-attribute = Mandatory
 *   caching-name = Cache

What's new

This section only lists the major changes between versions. If you need to know exactly what changed from one revision to the other, please consult the file REVISIONS in the distribution.

2.15 (August, 2003)
2.10 (October 25, 2002)
2.7 (June 27, 2002)
2.2 (Oct 30, 2001)
2.0
1.20

July 16, 2001

Created an EJBGen mailing-list.

1.18

Added support for ejbSelect (tag @select).

1.17

Some MessageDriven Bean tags are now available in two versions: one prefixed with "jms-" and one without it. The latest version of the EJB 2.0 specification removed the jms- prefix from those tags, so I'm just providing this for those of you using a version of WebLogic 6.0 that predates those changes. The available tags are:

Use whatever tag is appropriate for the version of Weblogic you are using (typically: those prefixed by jms- for 6.0 and 6.0 SP1 and the others for 6.1).

1.16

@ejb-ref has one new (mandatory) parameter: the JNDI name of the referenced EJB. This way, EJBGen will generate the corresponding in weblogic-ejb-jar.xml.

1.14

EJBGen supports ant, please see the ant section for more details.

1.12

If you are upgrading from an older version to EJBGen 1.12, you need to be aware of the following incompatible changes that have been made to the syntax of certain tags:

Also: the generated files now respect the package path. In other words, the deployment descriptors will be generated in the current directory while the Java files will be generated in their package path.

Credits

  • To Rickard Oberg for coming up with the idea of using Javadoc to generate EJB's (based on an article published in Javaworld.) Thanks, Rickard!
  • To Dimitri Rakitine and Andrew Montgomery for their restless beta debugging.
  • To Julian Sitkewich for offering the initial skeleton for build.xml

    Back to my
    home page