Telling JAWS about your tables

JAWS will use one different table for each of your CMP entity beans. The table for one entity bean will contain one column for each of the CMP fields of this entity.

By default, JAWS will create the tables for you. The name of the table will be the ejb-name of the bean, and the name of the columns will be the names of the CMP fields. The jdbc type and the sql type will be the ones given by the type-mapping. (see how the jdbc and sql type work in the section called “Defining a type mapping”)

However, you may want to override this behavior and tell JAWS which names/types to use. For example, you may want JAWS to use an already existing table. To do this, you must set these parameters in the <enterprise-beans> section of you jaws.xml file.

Example 1

You create an entity bean that will represent a class. You already have the table in your database, it was created using the following SQL statement:

CREATE TABLE CLASS (ID INTEGER, TEACHER VARCHAR(100), STUDENTNBR INTEGER);

This is how the your xml file will look like:

<jaws>
	<enterprise-beans>
		<entity>
			<ejb-name>ClassBean</ejb-name>
			<table-name>CLASS</table-name>
			<create-table>false</create-table>
			<cmp-field>
				<field-name>classId</field-name>
				<column-name>ID</column-name>
			</cmp-field>
			<cmp-field>
				<field-name>teacherName</field-name>
				<column-name>TEACHER</column-name>
			</cmp-field>
			<cmp-field>
				<field-name>studentCount</field-name>
				<column-name>STUDENTNBR</column-name>
			</cmp-field>
		</entity>
	</enterprise-beans>
</jaws> 
 

Example 2

Your Class bean has a String field to hold the Teacher name. You don't want to use the default mapping for a String (VARCHAR(256)) since a name is not that long. Your xml file will look like this:

<jaws>
	<enterprise-beans>
		<entity>
			<ejb-name>ClassBean</ejb-name>
			...
			<cmp-field>
				<field-name>teacherName</field-name>
				<column-name>TEACHER</column-name>
				<jdbc-type>VARCHAR</jdbc-type>
				<sql-type>VARCHAR(100)</sql-type>
			</cmp-field>
			...
		</entity>
	</enterprise-beans>
</jaws> 
 

Note that the contents of the <ejb-name> tag and of all the <field-name> tags must match the ones declared in ejb-jar.xml.