aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes ejbql-jboss problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "ejbql-jboss problem" Watch "ejbql-jboss problem" New topic
Author

ejbql-jboss problem

visshal patel
Greenhorn

Joined: Apr 01, 2004
Posts: 8
I am trying to deploy a simple CMP-entity bean on jboss3.2. On one of the EJBQL in ejb-jar.xml it gives "nosuchmethodexception". My files are as follows.
********************************************
ejb-jar.xml
*****************************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
<ejb-jar>
<description>ATF Book Bean</description>
<display-name>ATF Book</display-name>
<enterprise-beans>
<entity>
<description>Models a book</description>
<ejb-name>Book</ejb-name>
<home>com.vigorsoft.ejb.BookHome</home>
<remote>com.vigorsoft.ejb.Book</remote>
<ejb-class>com.vigorsoft.ejb.BookBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.vigorsoft.ejb.BookPK</prim-key-class>
<reentrant>False</reentrant>

<cmp-version>2.x</cmp-version>
<abstract-schema-name>BookBean</abstract-schema-name>
<cmp-field><field-name>id</field-name></cmp-field>
<cmp-field><field-name>author</field-name></cmp-field>
<cmp-field><field-name>title</field-name></cmp-field>
<cmp-field><field-name>publisher</field-name></cmp-field>
<cmp-field><field-name>usDollarPrice</field-name></cmp-field>

<query>
<query-method>
<method-name>findExpensiveBooks</method-name>
<method-params>
<method-param>double</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(b) from BookBean AS b WHERE b.usDollarPrice > ?1]]>
</ejb-ql>
</query>
<query>
<query-method>
<method-name>findByAuthor</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(b) from BookBean AS b WHERE b.author = ?1]]>
</ejb-ql>
</query>
</entity>
</enterprise-beans>

<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Book</ejb-name>
<method-intf>Remote</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

</ejb-jar>
***************************************************
jbosscmp-jdbc.xml
*****************************************************
<jbosscmp-jdbc>
<defaults>
<datasource>java:/PostgresDS</datasource>
<datasource-mapping>PostgreSQL</datasource-mapping>
</defaults>
<enterprise-beans>
<entity>
<ejb-name>Book</ejb-name>
<table-name>vp_book</table-name>
<create-table>true</create-table>

<cmp-field>
<field-name>id</field-name>
<column-name>id</column-name>
</cmp-field>

<cmp-field>
<field-name>author</field-name>
<column-name>author</column-name>
</cmp-field>

<cmp-field>
<field-name>title</field-name>
<column-name>title</column-name>
</cmp-field>

<cmp-field>
<field-name>publisher</field-name>
<column-name>publisher</column-name>
</cmp-field>

<cmp-field>
<field-name>usDollarPrice</field-name>
<column-name>usDollarPrice</column-name>
</cmp-field>
</entity>
</enterprise-beans>

</jbosscmp-jdbc>
************************************************************
Book.java
**********************************************************
package com.vigorsoft.ejb;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
/**
* @author vishalp
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public interface Book extends EJBObject {

public int getId() throws RemoteException;
public void setId(int newId) throws RemoteException;
public String getTitle() throws RemoteException;
public void setTitle(String newTitle) throws RemoteException;
public String getAuthor() throws RemoteException;
public void setAuthor(String newAuthor) throws RemoteException;
public String getPublisher() throws RemoteException;
public void setPublisher(String newPublisher) throws RemoteException;
public double getUsDollarPrice() throws RemoteException;
public void setUsDollarPrice(double newDollarPrice) throws RemoteException;
}
******************************************************
BookBean.java
********************************************************
package com.vigorsoft.ejb;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
/**
* @author vishalp
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public abstract class BookBean implements EntityBean {
EntityContext ctx;
public int id;
public String title;
public String author;
public String publisher;
public double usDollarPrice;

/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbActivate()
*/
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbLoad()
*/
public void ejbLoad() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbPassivate()
*/
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbRemove()
*/
public void ejbRemove()
throws RemoveException, EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbStore()
*/
public void ejbStore() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
*/
public void setEntityContext(EntityContext arg0)
throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#unsetEntityContext()
*/
public void unsetEntityContext() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}


/* Each time create() is invoked on the home interface,
ejbCreate() is invoked on our object with the same
arguments. */
public BookPK ejbCreate(int newId, String newTitle,
String newAuthor, String newPublisher,
double newUsDollarPrice)
throws EJBException, RemoteException, CreateException {
// Assign our instance variables based on the arguments
/* id = newId;
title = newTitle;
author = newAuthor;
publisher = newPublisher;
usDollarPrice = newUsDollarPrice;
*/
setId(newId);
setTitle(newTitle);
setAuthor(newAuthor);
setPublisher(newPublisher);
setUsDollarPrice(newUsDollarPrice);
return new BookPK(id);
}
/* After ejbCreate() is invoked, the system executes
ejbPostCreate(), once again with the same arguments as create()
and ejbCreate(). Our bean is simple enough that it doesn't
need to do anything in ejbPostCreate(). */
public void ejbPostCreate(int newId, String title,
String author, String publisher,
double usDollarPrice) { }
/* We need to write one "setter" and one "getter" for each public
instance variable. */
public abstract int getId();
public abstract void setId(int newId);
public abstract String getTitle();
public abstract void setTitle(String newTitle);
public abstract String getAuthor();
public abstract void setAuthor(String newAuthor);
public abstract String getPublisher();
public abstract void setPublisher(String newPublisher);
public abstract double getUsDollarPrice();
public abstract void setUsDollarPrice(double newUsDollarPrice);
}
*****************************************8
BookHome.java
***********************************************
package com.vigorsoft.ejb;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
/**
* @author vishalp
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public abstract class BookBean implements EntityBean {
EntityContext ctx;
public int id;
public String title;
public String author;
public String publisher;
public double usDollarPrice;

/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbActivate()
*/
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbLoad()
*/
public void ejbLoad() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbPassivate()
*/
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbRemove()
*/
public void ejbRemove()
throws RemoveException, EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#ejbStore()
*/
public void ejbStore() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
*/
public void setEntityContext(EntityContext arg0)
throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.EntityBean#unsetEntityContext()
*/
public void unsetEntityContext() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}


/* Each time create() is invoked on the home interface,
ejbCreate() is invoked on our object with the same
arguments. */
public BookPK ejbCreate(int newId, String newTitle,
String newAuthor, String newPublisher,
double newUsDollarPrice)
throws EJBException, RemoteException, CreateException {
// Assign our instance variables based on the arguments
/* id = newId;
title = newTitle;
author = newAuthor;
publisher = newPublisher;
usDollarPrice = newUsDollarPrice;
*/
setId(newId);
setTitle(newTitle);
setAuthor(newAuthor);
setPublisher(newPublisher);
setUsDollarPrice(newUsDollarPrice);
return new BookPK(id);
}
/* After ejbCreate() is invoked, the system executes
ejbPostCreate(), once again with the same arguments as create()
and ejbCreate(). Our bean is simple enough that it doesn't
need to do anything in ejbPostCreate(). */
public void ejbPostCreate(int newId, String title,
String author, String publisher,
double usDollarPrice) { }
/* We need to write one "setter" and one "getter" for each public
instance variable. */
public abstract int getId();
public abstract void setId(int newId);
public abstract String getTitle();
public abstract void setTitle(String newTitle);
public abstract String getAuthor();
public abstract void setAuthor(String newAuthor);
public abstract String getPublisher();
public abstract void setPublisher(String newPublisher);
public abstract double getUsDollarPrice();
public abstract void setUsDollarPrice(double newUsDollarPrice);
}
**************************************************
BookPK.java
****************************************************
package com.vigorsoft.ejb;
import java.io.Serializable;
/**
* @author vishalp
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class BookPK implements Serializable {

public int id;
public BookPK () { }
public BookPK(int value){
id = value;
}
public boolean equals(Object obj){
if (obj == null || !(obj instanceof BookPK))
return false;
if (((BookPK)obj).id == id)
return true;

return false;
}
public int hashCode (){
return id;
}

public String toString(){
return String.valueOf(id);
}
}
********************************************************

If anybody can help..
Thanks,
Vishal
Ade Barkah
Ranch Hand

Joined: Mar 17, 2004
Posts: 65
Hi Visshal,
Please post your BookHome class again (your BookHome above shows BookBean instead.) Likely the problem is a mismatch between the BookHome declarations and the ejb-jar.xml.
-Ade Barkah


-Ade<br /><a href="http://www.barkah.org" target="_blank" rel="nofollow">www.barkah.org</a>
visshal patel
Greenhorn

Joined: Apr 01, 2004
Posts: 8
Hi Ade,
Sorry about the mistake. Here is the code.
A point of note:- THIS SAME SET OF CODE WHEN DEPLOYED ON JBOSS-3.0.4 IT WORKS WITHOUT ANY PROBLEMS. I WONDER WHY IT WON'T WORK on Jboss-3.2.x
I also tried the Ship-Cabin Example from OReilly and even that won't work on Jboss-3.2.x for the same error situation.

/*
* BookHome.java
*
* Created on Mar 31, 2004 12:07:18 PM
*
* (C) Copyright VigorSoft Private Ltd, Baroda, India.
* All rights reserved
* The copyright to the computer program(s) herein is the property of
* VigorSoft Private Ltd, Baroda,India.The program(s) may be used and/or
* copied only with the written permission of VigorSoft Private Ltd,
* Baroda,India or in accordance with the terms and conditions stipulated
* in the agreement/contract under which the program(s) have been supplied.
************************************************************************
***********************Modification History*****************************
*Date Initials Change-Id Comments
************************************************************************
*
************************************************************************
*/
package com.vigorsoft.ejb;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import java.rmi.RemoteException;
import java.util.Collection;
/**
* @author vishalp
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public interface BookHome extends EJBHome {
/* Create a new instance of Book */
public Book create(int newId, String newTitle,
String newAuthor, String newPublisher,
double newUsDollarPrice)
throws RemoteException, CreateException;
/* Find a Book with the specified ID. The EJB container
implements this method for us automatically. */
public Book findByPrimaryKey (BookPK book)
throws RemoteException, FinderException;
/* Return a Collection of books that matches an author name. This
method is implemented automatically by the EJB container. */
public Collection findByAuthor (String authorName)
throws RemoteException, FinderException;
/* Return all of the Book objects in the database */
public Collection findAll() throws RemoteException, FinderException;

public Collection findExpensiveBooks(double dollar)
throws RemoteException, FinderException;
}
Ade Barkah
Ranch Hand

Joined: Mar 17, 2004
Posts: 65
Visshal,
Sorry for the late reply. If you haven't solved it yet, you'll need to define the findAll method in the ejb-jar.xml (unlike findByPrimaryKey which gets defined automatically by the container). E.g.,
<query>
<query-method>
<method-name>findAll</method-name>
<method-params />
</query-method>
<ejb-ql>
<![CDATA[SELECT OBJECT(B) FROM BookBean B]]>
</ejb-ql>
</query>
Regards,
-Ade Barkah
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: ejbql-jboss problem