deployment error on Sun JES when I map an entity bean to a view

Hi,

I got a deployment error when I try to map a CMP entity bean to a database view rather than a table. The system compain that the table is not found. I have set the property of the CMP bean as read-only in the descriptor.

My Working environment is:

Windows XP SP2

Oracle 8i,

Sun Java Enterprise System 8.1

in sun-ejb-jar.xml

<sun-ejb-jar>

<enterprise-beans>

<unique-id>0</unique-id>

<ejb>

<ejb-name>User</ejb-name>

<jndi-name>User</jndi-name>

<is-read-only-bean>true</is-read-only-bean>

</ejb>

<cmp-resource>

<jndi-name>jdbc/STARS_ORACLE</jndi-name>

<create-tables-at-deploy>true</create-tables-at-deploy>

</cmp-resource>

</enterprise-beans>

</sun-ejb-jar>

in sun-cmp-mappings.xml:

<entity-mapping>

<ejb-name>User</ejb-name>

<table-name>VW_EMP_RBS</table-name>

<cmp-field-mapping>

<field-name>staffNo</field-name>

<column-name>VW_EMP_RBS.STAFF_NO</column-name>

<fetched-with>

<default/>

</fetched-with>

</cmp-field-mapping>

............

</entity-mapping>

--

Error message:

[#|2006-08-02T09:45:55.919+0800|SEVERE|sun-appserver-ee8.1|javax.enterprise.sys tem.tools.deployment|_ThreadID=113;|Exception occured in J2EEC Phase

com.sun.enterprise.deployment.backend.IASDeploymentException: Error while running ejbc -- Fatal Error from EJB Compiler -- JDO74046: JDOCodeGenerator: Caught a MappingConversionException loading or creating mapping model for application 'app-ejb' module 'app-ejb': JDO71002: The schema file app-ejb does not contain a table named VW_EMP_RBS

at com.sun.ejb.codegen.CmpCompiler.compile(CmpCompiler.java:274)

at com.sun.ejb.codegen.IASEJBC.doCompile(IASEJBC.java:615)

at com.sun.ejb.codegen.IASEJBC.ejbc(IASEJBC.java:563)

at com.sun.enterprise.deployment.backend.EJBCompiler.preDeployModule(EJBCompiler.j ava:427)

at com.sun.enterprise.deployment.backend.EJBCompiler.compile(EJBCompiler.java:213)

at com.sun.enterprise.deployment.backend.ModuleDeployer.runEJBC(ModuleDeployer.jav a:967)

at com.sun.enterprise.deployment.backend.EjbModuleDeployer.deploy(EjbModuleDeploye r.java:176)

at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDepl oyer.java:140)

at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:146)

at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPh ase.java:71)

at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeplo ymentService.java:633)

at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentSe rvice.java:188)

at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentSe rvice.java:520)

at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:143)

at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:171)

|#]

[3289 byte] By [CornerStone] at [2007-11-14]
# 1
Once the tables are created by Java2DB in the database, please capture the schema by hand and package it into your ear.
mf125085 at 2007-7-7 > top of java,Application & Integration Servers,Application Servers...
# 2

The program to capture a database schema is located in the appserver's bin directory:

capture-schema -username name -password password -dburl url -driver

jdbcdriver -out aFilename

[-schemaname aSchemaname] [-table aTablename]*

The schema name should be your user name. Please don't use the -table argument. Capture all tables in your schema. You might have to reference the schema in sun-ejb-jar.xml.

Once you packaged the schema into your ear, you should disable Java2DB.

mf125085 at 2007-7-7 > top of java,Application & Integration Servers,Application Servers...
# 3

Java2DB is *not* involved here as your ejb-jar contains a sun-cmp-mappings.xml.

To sum up:

Capture your schema and package it into the ejb-jar. The schema is referenced from sun-cmp-mappings in the following way:

<sun-cmp-mappings>

<sun-cmp-mapping>

<schema>MySchema</schema>

<entity-mapping>

.....

</entity-mapping>

</sun-cmp-mapping>

</sun-cmp-mappings>

The schema entry should be the relative path from the root of the ejb-jar, w/o the .dbschema ending. Above entry points to a dbschema "MySchema.dbschema" in the root of the ejb-jar file.

mf125085 at 2007-7-7 > top of java,Application & Integration Servers,Application Servers...
# 4

thank you for the reply.

I didn't find the capture-schema command in the bin directory.

1. Do I have to re-install the JES?

2. Does your solution imply that I have to capture the database schema again once I modify the deployment descriptor file such as ejb-jar.xml, sun-ejb-jar.xml, sun-cmp-mappings.xml?

CornerStone at 2007-7-7 > top of java,Application & Integration Servers,Application Servers...
# 5

> 1. Do I have to re-install the JES?

In my environment capture-schema is in the appserver's bin directory:

$ ls -l SUNWappserver/bin/capture-schema

-rwxr-xr-x1 user group476 Aug 18 14:35 SUNWappserver/bin/capture-schema*

It's actually a shell script:

#!/bin/sh

#

# Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.

# Use is subject to license terms.

#

. "$HOME/SUNWappserver_9.0/config/asenv.conf"

"${AS_JAVA}/bin/java" -Xms24m -Xmx96m -cp "${AS_INSTALL}/lib/appserv-rt.jar":"${AS_INSTALL}/lib/appserv-cmp.jar":"${AS_IN STALL}/lib/dbschema.jar":"${AS_INSTALL}/lib/appserv-se.jar":"${AS_INSTALL}/lib/a ppserv-env.jar":"${CLASSPATH}" com.sun.jdo.spi.persistence.support.ejb.util.CaptureSchemaWrapper "${@}"

> 2. Does your solution imply that I have to capture

> the database schema again once I modify the

> deployment descriptor file such as ejb-jar.xml,

> sun-ejb-jar.xml, sun-cmp-mappings.xml?

You'd have to re-capture the schema every time the database tables are modified.

m_fuchs at 2007-7-7 > top of java,Application & Integration Servers,Application Servers...