EJBGen is an Enterprise JavaBeans 2.x code generator. If you annotate your Bean class file with JDK 1.5 annotations, you can use EJBGen to generate the Remote and Home classes and the deployment descriptor files for an EJB application.
BEA recommends that you use EJBGen to generate deployment descriptors; this BEA best practice allows for easier and simpler maintenance of EJBs. If you use EJBGen, you need to write and annotate only one bean class file, which simplifies writing, debugging, and maintenance. The following sections provide instructions on using EJBGen and define EJBGen command options and annotations:
In this release of WebLogic Server, EJBGen and associated classes are included in weblogic.jar in the WL_HOME/server/lib of the WebLogic Server distribution. To use EJBGen, make sure weblogic.jar is in your CLASSPATH. EJBGen annotations can be found in the weblogic.ejbgen package.
If you have installed BEA WebLogic Server examples, see WL_HOME\samples\server\examples\src\examples\ejb\ejb20\ and WL_HOME\samples\server\examples\src\examples\ejb\ejb21\ for an application that uses EJBGen.
Invoking EJBGen
Use this command to run EJBGen on a bean source file:
com.bea.wls.ejbgen.EJBGen
Note:
To run this command, weblogic.jar must be in your CLASSPATH.
If you are invoking EJBGen for an EJB that has relationships with other EJBs, invoke the related EJBs by naming them, following your EJB, in the invocation, as follows:
If invoked with this option, EJBGen will not generate any classes but will search the classes supplied on the command line for tags that are not valid EJBGen tags.
-classPath [directory]
N/A
Specifies the directory where the class loader can find dependent classes that are in .class format.
To specify more than one class path, separate paths with a semicolon (;).For instance: -classpath /dir1;/dir2
If dependent classes are in .java format, use -sourcePath instead.
-d [directory]
N/A
The directory under which all the files will be created.
-ddOnlyGen [boolean]
0
Tells the compiler to generate only the deployment descriptor files.
-descriptorDir [directory]
N/A
The directory under which all the descriptor files will be created, relative to the output directory specified with the -d [directory] option.
-docTag tagName
N/A
If specified, EJBGen prints out the detailed documentation for this tag, including all the recognized attributes. 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.
-docTags
N/A
Print 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
N/A
Same as -docTags, but generates an HTML document.
-ejbPrefix [string]
" "
The prefix to use when generating the EJB class.
-ejbSuffix [string]
Bean or EJB
The suffix to use when generating the EJB class.
-ejbgenQuiet [boolean]
N/A
Make EJBGen less verbose.
-ejbgenVerbose [boolean]
N/A
Verbose mode.
-errorFile
N/A
The path of the file where errors will be redirected.
-exitOnError [boolean]
N/A
EJBGen should exit in case of an error.
-homeBaseClass [string (className)]
N/A
The base class for home remote interfaces.
-extractTemplates [directory]
N/A
The directory where to extract the templates.
-forceGeneration [boolean]
N/A
Force the generation of all files regardless of time stamps.
-homeBaseClass [string (className)]
N/A
The base class for home remote interfaces.
-ignorePackage
N/A
If this flag is set, EJBGen ignores the package name of the Java files it generates and creates those in the output directory as specified by the -d flag (or in the current directory if no -d was specified).
-jndiPrefix [string]
" "
The prefix to use for @remoteJndiName and @localJndiName
-jndiSuffix [string]
" "
The suffix to use for @remoteJndiName and @localJndiName
-localBaseClass [string (className)]
N/A
The base class for local interfaces.
-localHomeBaseClass [className]
N/A
The base class for local home interfaces.
-localHomePrefix [string]
" "
The prefix to use when generating the local EJB class.
-localHomeSuffix [string]
LocalHome
The suffix to use when generating the local EJB class.
-localPrefix [string]
" "
The prefix to use when generating the local EJB class.
-localSuffix [string] (
" "
The suffix to use when generating the local EJB class.
-noDDGen [boolean]
0s
The compiler does not generate the deployment descriptor files.
-noImports [boolean]
false
Disable propagation of java imports to generated classes.
The prefix to use when generating the remote EJB home class.
-remoteHomeSuffix [string]
" "
The suffix to use when generating the remote EJB home class.
-remotePrefix [string]
" "
The prefix to use when generating the remote EJB class.
-remoteSuffix [string]
" "
The suffix to use when generating the remote EJB class.
-source [version number]
1.5
Version of the JDK to use.
-sourcepath [directory]
N/A
Specifies the directory where the class loader can find dependent classes that are in .java format.
To specify more than one source path, separate paths with a semicolon (;).For instance: -sourcePath /dir1;/dir2
If dependent classes are in .class format, use -classPath instead.
-templateDir [directory]
N/A
The directory where the templates are stored.
-toStringForPrimitivesOnly
N/A
If specified, the toString() methods of value objects only display container-managed persistence fields that are primitives. This flag fixes the problem of circular references between value objects (AValue.toString() invoking BValue.toString() invoking AValue.toString(), etcetera).
-valueBaseClass [string (class name)]
N/A
The base class of the value class generated by EJBGen.
-valueObjectPrefix [string]
N/A
The prefix to use when generating the value object class.
-valueObjectSuffix [string]
N/A
The suffix to use when generating the value object class.
-valuePackage [string (package name)]
N/A
Package the value classes belong to.
-verbose [boolean]
false
Display more information.
-workshopDocTags [boolean]
N/A
Display the help in BEA Workshop for WebLogic Platform 9.2 HTML format.
-xmlEncoding [string]
N/A
The encoding to use when generating XML files (default: UTF-8).
Using Key EJBGen Features
These sections describe key EJBGen features and how to use them:
EJBGen recognizes two kinds of variables in a properties file: user variables and predefined variables.
Using User Variables
EJBGen tags can use variables instead of strings. These variables must be enclosed with "${"and "}".
Variables can be used anywhere after an EJBGen tag, so they can contain whole tag definitions.
Using 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. Recognized variables are:
remote.baseClass
If specified, the value of this variable will be used as the base class for all generated remote classes.
home.baseClass If specified, the value of this variable will be used as the base class for all generated remote home classes.
local.baseClass
If specified, the value of this variable will be used as the base class for all generated local classes.
localHome.baseClass
If specified, the value of this variable will be used as the base class for all generated local home classes.
value.baseClass
If specified, the value of this variable will be used as the base class for all generated value classes.
value.package
If specified, the value of this variable will be used as the package for all generated value classes.
value.interfaces
If specified, the value of this variable will be used as the interfaces the value class should implement. This variable can be a list of interfaces separated by commas.
You can make these variables more specific by prefixing them with an EJBName. For example, consider the following property file.
All homes generated by EJBGen extend the class BaseHome except the home of EJB “Account”, which extends BaseAccountHome.
Surround Attributes that Contain Spaces With Double Quotes
When you specify an attribute that contains spaces, surround the attribute value with double quotes. For example:
group-names = "group1, group2"
EJBGen Supports Tag Inheritance
One of the main features in EJBGen 2.x is tag inheritance. You inherit EJBGen annotations the same way you do in Java. For example, assume that you have an EJB named AccountEJB with a base class BaseAccount, as in Listing 8-6:
weblogic.ejbgen.JndiName
Listing 8-6 Tag Inheritance
@JndiName(remote = "BaseRemote")
public class BaseAccount implements EntityBean { // ... }
Now, define your EJB class:
@Entity(ejbName = containerManaged, tableName = ejbAccounts, datasourceJndiName = examples-dataSource-demoPool) //Note that we inherit the JNDI name defined in BaseAccount public class AccountEJB extends BaseAccount { // ...
Examples of EJBGen Tag Usage
These sections contain example source code annotated with EJBGen tags.
Mapping an Entity Bean to Several Tables with EJBGen
By default, entity beans are mapped to one table, with the attribute tableName on the tag @Entity. If you want to map your entity bean to more than one table, you can use the table-name attribute on individual @CmpFields provided the CMP fields are primary key fields that are mapped to corresponding primary key columns in each table. Any container-managed persistence fields that do not have a tableName attribute will use the table specified on @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 tableName attribute (and also on a column). Make sure that the number of tables matches the number of columns, and that the columns exist in the corresponding table.
Specifying Relationship Caching with EJBGen Tags
You can specify relationship caching elements with the @RelationshipCaching tag. This element 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, @RelationshipCaching has two attributes, id and parentId. These attributes do not correspond to any XML, they simply allow you to specify your tree structure.
For example, if a cachingElement A needs to have two children elements B and C, all you need to specify is an id for A (say “root0”) and a parentId for B and C equal to that name.
Unidirectional relationships are achieved by specifying only the first two parameters of the relation tag (no CMR_field, no join table).
Note:
"Join table" was called "joint table" in pre-9.0 releases of WebLogic Server.
Many-to-many relationships must specify an extra table (parameter "join table") which must contain at least two columns. The names of these columns must match the names of the columns containing the foreign keys of the two beans being joined.
Upgrading Relationships to Use Local Interfaces
If you have EJBs based on a version of the EJB 2.0 specification that predates PFD2, you must update them. As of PFD2, relationships must be based on local interfaces, not remote ones. To upgrade your EJBs:
Add a JNDI name for your local home interface:
@JndiName remote = AccountHome local = AccountLocalHome
Add @LocalMethod tags to any method you want to see appear on the local home interface. A method can have both @LocalMethod and @RemoteMethod.
Change the return type of your container-managed relationship (CMP) accessing methods to that of the local EJB object (this only applies to single-valued CMR fields since multi-valued CMR fields are collections. Keep in mind that these collections contain Local EJB objects):
@CmrField
@RemoteMethod @LocalMethod
abstract public LocalCustomer getCustomer();
Enum Attribute Constant Values
The following enum values are used for many of the EJBGen attributes.
Constants.Bool
Valid values for Constant.Bool are as follows:
Constants.Bool.UNSPECIFIED
Constants.Bool.TRUE
Constants.Bool.FALSE
Constants.TransactionAttribute
Valid values for Constants.TransactionAttribute are as follows:
Constants.TransactionAttribute.UNSPECIFIED
Constants.TransactionAttribute.NOT_SUPPORTED
Constants.TransactionAttribute.SUPPORTS
Constants.TransactionAttribute.REQUIRED
Constants.TransactionAttribute.REQUIRES_NEW
Constants.TransactionAttribute.MANDATORY
Constants.TransactionAttribute.NEVER
Constants.IsolationLevel
Valid values for Constants.IsolationLevel are as follows:
The default value for this attribute is UNSPECIFIED.
String.
No.
groupNames
Comma-delimited names of the groups this field belongs to. Surround the list of group names with double quotes.
The default value for this attribute is UNSPECIFIED.
String
No.
orderingNumber
The number where this field must appear in signatures and constructors. For this ordering to work, all cmr and cmp fields must set this attribute to a distinct numeric value.
The default value for this attribute is 0.
String
No.
excludeFromValueObject
If True, this field will not be generated in the value object.
See Constants.Bool for the list of valid values for this attribute.
Comma-delimited names of the groups this field belongs to. Surround the list of group names with double quotes.
The default value for this attribute is UNSPECIFIED.
String
No.
orderingNumber
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 to a distinct numeric value.
The default value for this attribute is UNSPECIFIED.
String
No.
excludeFromValueObject
If True, this field will not be generated in the value object.
See Constants.Bool for the list of valid values for this attribute.
For an EJB that uses Optimistic or ReadOnly concurrency, specifies whether the EJB is invalidated when it is updated by a member of a cluster to which it is deployed. When true, the container does not send out multicast invalidation messages when such EJBs are updated.
See Constants.Bool for the list of valid values for this attribute.
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.
Determines which Home this finder will be generated on. If the value of this attribute is unspecified, the finder will be generated on both the Remote and Local Home.
Valid values for this attribute are as folows:
Finder.GenerateOn.UNSPECIFIED
Finder.GenerateOn.LOCAL
Finder.GenerateOn.REMOTE
The default value is Finder.GenerateOn.UNSPECIFIED.
Enum
No.
comment
Defines a comment that will be reproduced above the generated finder Java method.
The default value for this attribute is UNSPECIFIED.
String
No
id
The identity of this tag (used for tag inheritance only).
The default value for this attribute is UNSPECIFIED.
String
No
cachingName
Specifies the name of an eager relationship caching.
The default value for this attribute is UNSPECIFIED.
String
No
groupName
Names the group for the WebLogic Server query.
The default value for this attribute is UNSPECIFIED.
String
No
maxElements
Specifies the maximum number of elements that should be returned by a multi-valued query.
The default value for this attribute is UNSPECIFIED.
String
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.
The default value for this attribute is UNSPECIFIED.
String
No
sqlSelectDistinct
Determines whether the generated SQL SELECT will contain a DISTINCT qualifier.
The default value is arSettings.CreateTables.UNSPECIFIED.
Enum
No.
ejbClientJar
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.
The default value of this attribute is UNSPECIFIED.
String
No
enableBeanClassRedeploy
Determines whether this EJB can be redeployed without redeploying the entire module.
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.
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.
Specifies the maximum number of beans in the free pool.
The default value of this attribute is UNSPECIFIED.
String
No
defaultTransaction
Specifies the transaction attribute to be applied to all methods that do not have a specific transaction attribute setting.
Valid values for this attribute are:
MessageDriven.DefaultTransaction.UNSPECIFIED
MessageDriven.DefaultTransaction.NOT_SUPPORTED
MessageDriven.DefaultTransaction.REQUIRED
The default value is MessageDriven.DefaultTransaction.UNSPECIFIED.
Enum
No
runAsIdentityPrincipal
Deprecated. Use runAsPrincipalName instead.
String
No
runAsPrincipalName
Gives the name of the principal in case the role maps to several principals.
The default value for this attribute is UNSPECIFIED.
String
No
dispatchPolicy
Specifies the dispatch policy queue for this bean.
The default value of this attribute is UNSPECIFIED.
String
No
remoteClientTimeout
Specifies the length of time that a remote RMI client will wait before it will time out.
The default value of this attribute is UNSPECIFIED
String
No
passivateAsPrincipalName
Names the principal to be used when ejbPassivate would otherwise run with an anonymous principal.
The default value of this attribute is UNSPECIFIED.
String
No
acknowledgeMode
Specifies the acknowledgement mode of this message-driven bean.
Valid values for this attribute are:
MessageDriven.AcknowledgeMode.UNSPECIFIED
MessageDriven.AcknowledgeMode.AUTO_ACKNOWLEDGE
MessageDriven.AcknowledgeMode.DUPS_OK_ACKNOWLEDGE
The default value is MessageDriven.AcknowledgeMode.UNSPECIFIED.
Enum
No
runAs
Specifies the role-name for this EJB.
The default value of this attribute is UNSPECIFIED.
String
No
jmsClientId
The client ID of this EJB.
The default value of this attribute is UNSPECIFIED.
String
No
createAsPrincipalName
Names the principal to be used when ejbCreate would otherwise run with an anonymous principal.
The default value of this attribute is UNSPECIFIED.
String
No
networkAccessPoint
Assigns a custom network channel that the EJB will use for network communications. A network channel defines a set of connection attributes.
The default value of this attribute is UNSPECIFIED.
String
No
messagingType
The default value of this attribute is UNSPECIFIED.
String
No
initSuspendSeconds
The initial number of seconds to suspend an MDB’s JMS connection when the EJB container detects a JMS resource outage.
The default value of this attribute is 0.
int
No
maxSuspendSeconds
Specifies the maximum number of seconds to suspend an MDB’s JMS connection when the EJB container detects a JMS resource outage.
The default value of this attribute is 0.
int
No
generateUniqueJmsClientId
Indicates whether or not you want the EJB container to generate a unique client-id for every instance of an MDB which makes is easier to deploy durable MDBs to multiple server instances in a WebLogic Server cluster.
Specifies the name of the relationship. Use the same name on both ends of a relationship (this constraint also applies to unidirectional relationships).
String
Yes
jointTable
Deprecated. BEA recommends that you use joinTable instead.
String
No
joinTable
Only needed in a many-to-many relationship. The name of an existing table that will be used to hold the join table containing the relationships. If you are using a compound primary key, specify a set of corresponding foreign keys separated by a comma.
The default value of this attribute is UNSPECIFIED.
String
No
fkColumn
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.
The default value of this attribute is UNSPECIFIED.
String
No
roleName
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.
The default value of this attribute is UNSPECIFIED.
String
No
foreignKeyTable
The name of a DBMS table that contains a foreign-key.
The default value of this attribute is UNSPECIFIED.
String
No
primaryKeyTable
The name of a DBMS table that contains a primary-key.
The default value of this attribute is UNSPECIFIED.
String
No
cmrField
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.
The default value of this attribute is UNSPECIFIED.
String
No
dbCascadeDelete
Determines whether a cascade delete will use the built-in cascade delete facilities of the underlying DBMS.
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.
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.
Specifies the number where this method must appear in the generated class.
The default value of this attribute is UNSPECIFIED.
String
No
ejbQl
Specifies the EJB-QL that defines this select method. The method name must start with ejbSelect.
The default value of this attribute is UNSPECIFIED.
String
No
weblogicEjbQl
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.
The default value of this attribute is UNSPECIFIED.
String
No
resultTypeMapping
Specifies whether the returned objects are mapped to EJBLocalObject or EJBObject.
Valid values for this attribute are:
Select.ResultTypeMapping.UNSPECIFIED
Select.ResultTypeMapping.LOCAL
Select.ResultTypeMapping.REMOTE
The default value is Select.ResultTypeMapping.UNSPECIFIED.
Specifies the maximum duration an EJB remains cached.
The default value of this attribute is UNSPECIFIED.
String
No
type
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.
Valid values for this attribute are:
Session.SessionType.UNSPECIFIED
Session.SessionType.STATELESS
Session.SessionType.STATEFUL
The default value Session.SessionType.UNSPECIFIED.
Enum
No
removeAsPrincipalName
Names the principal to be used when ejbRemove would otherwise run with an anonymous principal.
The default value of this attribute is UNSPECIFIED.
String
No
transTimeoutSeconds
Specifies the transaction timeout (in seconds).
The default value of this attribute is UNSPECIFIED.
String
No
transactionType
Specifies who manages the transactions for this EJB.
Valid values for this attribute are:
Session.SessionTransactionType.UNSPECIFIED
Session.SessionTransactionType.BEAN
Session.SessionTransactionType.CONTAINER
The default value Session.SessionTransactionType.UNSPECIFIED.
Enum
No
allowConcurrentCalls
Specifies whether to allow concurrent calls on that EJB.
Names class to be used for routing home method calls.
The default value of this attribute is UNSPECIFIED.
String
No
createAsPrincipalName
Names the principal to be used when ejbCreate would otherwise run with an anonymous principal.
The default value of this attribute is UNSPECIFIED.
String
No
networkAccessPoint
Assigns a custom network channel that the EJB will use for network communications. A network channel defines a set of connection attributes.
The default value of this attribute is UNSPECIFIED.
String
No
weblogic.ejbgen.SqlFinder
Target: Class
Attributes
Table E-38 SqlFinder EJBGen Annotation Attributes
Attribute
Description
Data Type
Required?
sql
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.
String
Yes
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.
String
Yes
maxElements
Specifies the maximum number of elements that should be returned by a multi-valued query.
The default value of this attribute is UNSPECIFIED.
String
No
includeUpdates
Determines whether updates made during the current transaction must be reflected in the result of a query.
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.
Specifies the EJB QL request as it will appear in the deployment descriptor.
The default value of this attribute is UNSPECIFIED.
String
No
transactionAttribute
Specifies thetransaction 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.
This annotation does not have any attributes, other than the array of weblogic.ejbgen.SqlFinder annotations.
weblogic.ejbgen.SqlShape
Target: Class
Attributes
Table E-39 SqlShape EJBGen Annotation Attributes
Attribute
Description
Data Type
Required?
name
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.
String
Yes
relationNames
Name of the SQL Shape to use for this finder query
The default value of this attribute is an empty array.
Array of String
No.
tables
Name of the SQL Shape to use for this finder query.
The default value of this attribute is an empty array.