If you have developed Enterprise JavaBeans in another development environment and plan to continue development of these EJBs in WebLogic Workshop, you can import these beans into an EJB project. To do so you must have the EJB JAR and the source code of the EJBs. An EJB Jar typically will contain multiple EJBs that can be imported at the same time. In this step of the tutorial you will import one entity bean.
The tasks in this step are:
Note. If you have developed EJBs in another development environment and plan to reuse these EJBs in a WebLogic Workshop application, but are not planning to continue development on these beans, you only have to add the EJB JAR to the application. For more information, see How Do I: Add an Existing Enterprise JavaBean to an Application?
[BEA_HOME]\weblogic81\samples\platform\tutorial_resources\EJBTutorial\import_jar\ejb20_relationships_bands.jar
[BEA_HOME]\weblogic81\samples\platform\tutorial_resources\EJBTutorial\import_src_dir
To Inspect the Imported Entity Bean
The Application tab displays the BandBean that has been imported. Notice that the package name of the bean is reflected in the directory structure. In addition to the entity bean, a regular java class, which will be used as a dependent value class, has been imported.
The Band EJB in Design View should look like this:
If you have developed Enterprise JavaBeans before, you might notice that the BandBean entity bean is represented by one file with an ejb extension, instead of several java files for the class definition and the definition of the various interfaces. In addition, when you double-click BandBean.ejb and go to Source View, you will notice special tags with the prefix ejbgen. These ejbgen tags are for instance used to mark methods to be exposed in remote and home interfaces, mark relationship fields, and describe EJB QL queries directly in the bean class. Instead of using separate classes for the various interfaces and instead of directly changing the deployment descriptor, WebLogic Workshop uses these tags to contain all the bean's information in one file. When you build an EJB Project, the WebLogic tool uses these tags to generate the various interfaces and to generate the appropriate deployment descriptor. For more information, see Getting Started with EJB Project or the Getting Started: Enterprise JavaBeans tutorial.
The Band bean defines three CMP fields to represent bands: (1) the band founder, (2) the name of the band, and (3) the start date when the band was founded. The name field is the primary key field. In other words, the assumption is made that each band has a unique name. All fields are read-only, that is, no setter methods are defined for these fields to make changes. The Band bean has three methods. There is one ejbCreate method to create a new band object, and there are two finder methods: the findByName methods returns the band object that matches a name argument, and the findAll method returns all band objects stored in the database. The Property Editor reveals that the ejb-name is BandEJB, the data-source-name is cgSampleDataSource and the table-name is bands. Also notice in the JAR Settings section that create-tables is set to CreateOnly. The latter setting means that when you build and deploy this bean, the table will be automatically created for you. To learn more about the other table creation options set with this property, see @ejbgen:jar-settings Annotation. Notice that the create-tables setting is part of the JAR settings. In other words, for every entity bean created as part of this project, the same table creation setting applies.
In this tutorial you will be building the EJBs frequently to verify that changes were made correctly:
If you encounter a build error, verify that both BandBean.ejb and BandInfo.java were imported successfully. If this is not the case, delete the imported files and repeat the import steps above. In particular make sure that you are pointing at the correct folder containing the EJB source files.
If you encounter a deployment error in addition to the expected deployment error described above, it might be related to the underlying data source: verify that you are working in the workshop domain by selecting Tools-->WebLogic Server-->Server Properties. The Server Home Directory should point to the workshop domain.
Click one of the following arrows to navigate through the tutorial: