Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

try to solve cmp exception over weblogic8.1

 
Abhishek Srivastava
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I have created an ejb.jar while making connectivity with Oracle 9i database on weblogic server8.1 with following files

1. Remote interface


public interface EjbRemote extends EJBObject
{
public String getId() throws RemoteException;
public String getName() throws RemoteException;
public String getPosition() throws RemoteException;
public int getSalary() throws RemoteException;
}

2. Home interace



public interface EjbHome1 extends EJBHome
{
public EjbRemote create(String id,String name,String position,int salary)throws CreateException,RemoteException;
public EjbRemote findByPrimaryKey(String id)throws RemoteException,FinderException;
}

3. Bean class


public abstract class EjbBean implements EntityBean
{
public abstract void setId(String id);
public abstract void setPosition(String position);
public abstract void setName(String name);
public abstract void setSalary(int salary);

public abstract String getId();
public abstract String getName();
public abstract String getPosition();
public abstract int getSalary();

public String ejbCreate(String id,String name,String position,int salary)throws CreateException
{
System.out.println("MY CMP");
setId(id);
setName(name);
setPosition(position);
setSalary(salary);
return null;
}

public void ejbPostCreate(String id,String name,String position,int salary)throws CreateException{}

public void ejbActivate()throws RemoteException{}

public void ejbPassivate()throws RemoteException{}

public void ejbStore()throws RemoteException{}

public void ejbLoad()throws RemoteException{}

public void ejbRemove()throws RemoteException{}

EntityContext ctx;

public void setEntityContext(EntityContext ctx)
{
this.ctx=ctx;
}

public void unsetEntityContext()
{
ctx=null;
}
}

4. client programmer

public class CmpClient
{
public static void main(String s[])
{
try
{
Properties prop=new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
prop.put(Context.PROVIDER_URL,"t3://localhost:7001");
Context context=new InitialContext(prop);
Object object=context.lookup("abhi");
EjbHome1 home=(EjbHome1)PortableRemoteObject.narrow(object,EjbHome1.class);
EjbRemote remote=home.findByPrimaryKey("a01");
System.out.println("My id is:"+remote.getId());
System.out.println("My name is:"+remote.getName());
System.out.println("My position is:"+remote.getPosition());
System.out.println("My salary is:"+remote.getSalary());
}
catch(Exception c)
{
System.out.println(c.getMessage());
}

}
}

5. Now i put 3 xml's inside META_INF
i.e

a) ejb-jar.xml

<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>abc</ejb-name>
<home>EjbHome1</home>
<remote>EjbRemote</remote>
<ejb-class>EjbBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>player</abstract-schema-name>
<cmp-field>
<field-name>id</field-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
</cmp-field>
<cmp-field>
<field-name>position</field-name>
</cmp-field>
<cmp-field>
<field-name>salary</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
</entity>
</enterprise-beans>

<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>abc</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

</ejb-jar>

b) weblogic-cmp-rdbms-jar.xml

<weblogic-rdbms-jar>
<weblogic-rdbms-bean>
<ejb-name>abc</ejb-name>
<data-source-name>mydatasource</data-source-name>

<table-map>
<table-name>player</table-name>
<field-map>
<cmp-field>id</cmp-field>
<dbms-column>id</dbms-column>
</field-map>
<field-map>
<cmp-field>name</cmp-field>
<dbms-column>name</dbms-column>
</field-map>
<field-map>
<cmp-field>position</cmp-field>
<dbms-column>position</dbms-column>
</field-map>
<field-map>
<cmp-field>salary</cmp-field>
<dbms-column>salary</dbms-column>
</field-map>
</table-map>
</weblogic-rdbms-bean>

</weblogic-rdbms-jar>

c)weblogic-ejb-jar.xml

<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>abc</ejb-name>

<reference-descriptor>
<resource-description>

<res-ref-name>mydatasource</res-ref-name>
<jndi-name>myjndi</jndi-name>

</resource-description>
</reference-descriptor>



<entity-descriptor>
<persistence>
<persistence-use>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>7.0</type-version>
<type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
</persistence-use>
</persistence>
</entity-descriptor>

<jndi-name>abhi</jndi-name>

</weblogic-enterprise-bean>

</weblogic-ejb-jar>

Then i made connection pools with poolname as mypool
datasource as mydatasource
jndi-name as myjndi

and after compressing into entity.jar ,i deployed .
But the weblogic server throws following exception as :

i.e

--------------- nested within: ------------------
weblogic.management.ManagementException: - with nested exception:
[weblogic.management.ApplicationException:
Exception:weblogic.management.ApplicationException: Prepare failed. Task Id = 0
Module: entity Error: [EJB:011024]The XML parser encountered an error i
n your deployment descriptor. Please ensure that your deployment descriptor corr
esponds to the format in the DTD. The error was:
Error parsing file 'META-INF/weblogic-ejb-jar.xml' at line: 42 column: 30. The
content of element type "weblogic-enterprise-bean" must match "(ejb-name,(entit
y-descriptor|stateless-session-descriptor|stateful-session-descriptor|message-dr
iven-descriptor)?,transaction-descriptor?,iiop-security-descriptor?,reference-de
scriptor?,enable-call-by-reference?,clients-on-same-server?,(run-as-identity-pri
ncipal|run-as-principal-name)?,create-as-principal-name?,remove-as-principal-nam
e?,passivate-as-principal-name?,jndi-name?,local-jndi-name?,dispatch-policy?)"..

]
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(S
laveDeployer.java:2491)
at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(Sla
veDeployer.java:798)
at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDepl
oyer.java:507)
at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDep
loyer.java:465)
at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHan
dler.java:25)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
>

Now plz tell me where i made it wrong.I given lt as you told but it throws exception .

Plz Try to solve it.

Thanks.

[ February 11, 2006: Message edited by: Mr. java srivastava ]

[ February 11, 2006: Message edited by: Mr. java srivastava ]
[ February 12, 2006: Message edited by: Mr. java srivastava ]
 
Marko Sibakov
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked your persistence definitons very quickly and it seems that you have wrong tag name in weblogic-ejb-jar.xml

<persistence-type>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>7.0</type-version>
<type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
</persistence-type>

shoud be

<persistence-use>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>7.0</type-version>
<type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
</persistence-use>


More info from http://edocs.bea.com/wls/docs70/ejb/reference.html

Please tell me if this solve your problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic