• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Got exception when running Headfirst Customer find method

 
David Chan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I can run the create method successully but when I try to run the find method, the client got the following message:

got a context
did the narrow
org.omg.CORBA.UNKNOWN: vmcid: 0x0 minor code: 0 completed: Maybe
at com.sun.corba.ee.internal.core.UEInfoServiceContext.<init>(UEInfoServiceContext.java:36)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27
)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at com.sun.corba.ee.internal.core.ServiceContextData.makeServiceContext(ServiceContextData.java:115)
at com.sun.corba.ee.internal.core.ServiceContexts.<init>(ServiceContexts.java:110)



When I open the j2ee server log ($J2EE_HOME\logs\mcqapp_lab1\j2ee\j2ee\error.log), the file shows:

ejb20Finder method = public abstract java.util.Collection headfirst.CustomerHome.findByCreditLimit(double) throws javax.ejb.FinderException,java.rmi.RemoteException
ejb20Finder ejbql = SELECT OBJECT(o) FROM CustomerBeanTable AS o WHERE o.limit = ?1
ejb20Finder query = sql not generated yet
javax.ejb.EJBException: nested exception is: SQL Exception: Syntax error: Encountered "sql" at line 1, column 1.
SQL Exception: Syntax error: Encountered "sql" at line 1, column 1.
at c8e.p.i._f1(Unknown Source)
at c8e.p.q._b84(Unknown Source)
at c8e.p.q.handleException(Unknown Source)
at c8e.p.n.handleException(Unknown Source)
at c8e.p.p.handleException(Unknown Source)
at c8e.p.g.<init>(Unknown Source)
at c8e.ct.a.<init>(Unknown Source)
at c8e.ct.e.newLocalPreparedStatement(Unknown Source)
at c8e.p.n.prepareStatement(Unknown Source)
at c8e.ct.e.prepareStatement(Unknown Source)
at c8e.p.n.prepareStatement(Unknown Source)

It seems there is something wrong in the EJB-SQL select statement, however,
the ejb application passed the Verifer checking. Anyone know how to solve problem? Please help. Thank you.

--- Development environment
OS: NT4.0 with sp 6
j2se ver: 1.4.2_03
j2ee ver: 1.3.1
ejb IDE: java deploytool
database: java/cloudscape

--- Deployment Descriptor
<ejb-jar>

<display-name>Ejb1</display-name>

<enterprise-beans>

<entity>

<display-name>CustomerBean</display-name>

<ejb-name>CustomerBean</ejb-name>

<home>headfirst.CustomerHome</home>

<remote>headfirst.Customer</remote>

<ejb-class>headfirst.CustomerBean</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>CustomerBeanTable</abstract-schema-name>

<cmp-field>

<description>no description</description>

<field-name>last</field-name>

</cmp-field>

<cmp-field>

<description>no description</description>

<field-name>limit</field-name>

</cmp-field>

<cmp-field>

<description>no description</description>

<field-name>first</field-name>

</cmp-field>

<cmp-field>

<description>no description</description>

<field-name>custAddress</field-name>

</cmp-field>

<cmp-field>

<description>no description</description>

<field-name>pK</field-name>

</cmp-field>

<primkey-field>pK</primkey-field>

<security-identity>

<description></description>

<use-caller-identity></use-caller-identity>

</security-identity>

<query>

<description></description>

<query-method>

<method-name>findByCreditLimit</method-name>

<method-params>

<method-param>double</method-param>

</method-params>

</query-method>

<ejb-ql>SELECT OBJECT(o) FROM CustomerBeanTable AS o WHERE o.limit = ?1</ejb-ql>

</query>

</entity>

</enterprise-beans>


--- CustomerHome.java source
package headfirst;

import javax.ejb.*;
import java.rmi.RemoteException;
import java.util.Collection;

public interface CustomerHome extends EJBHome {
public Customer create(String last, String first, String addr, String ID) throws CreateException, RemoteException;
public Customer findByPrimaryKey(String key) throws FinderException, RemoteException;
public Collection findByCreditLimit(double greaterThanAmt) throws FinderException, RemoteException;
}

--- CustomerClient.java source
Context ic = new InitialContext();
System.out.println("got a context");

Object o = ic.lookup("Customer");
System.out.println("got an object" + o);

CustomerHome home = (CustomerHome) PortableRemoteObject.narrow(o, CustomerHome.class);
System.out.println("did the narrow");

Collection collection = home.findByCreditLimit(100.00);
System.out.println("did the find");
 
Roger Yates
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,

The following line looks suspicious to me:
ejb20Finder query = sql not generated yet


It just so happens I'm running through the J2EE Tutorial and recently pressed a 'Generate Default SQL' button that takes EJB-QL and turns it into SQL. Sounds like it fits the bill.
Here's where it is:
1. Launch the deploytool
2. Select the entity bean for which you wrote the EJB-QL
3. Click the 'Entity' tab.
4. Click the 'Deployment Settings' button
5. Click the 'Generate Default SQL' button
6. Redeploy your application & I'm betting it'll run some SQL this time!

Cheers,
Roger
[ September 09, 2004: Message edited by: Roger Yates ]
 
Sundari Lingaiah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

<query>

<description></description>

<query-method>

<method-name>findByCreditLimit</method-name>

<method-params>

<method-param>double</method-param>

</method-params>

</query-method>

<ejb-ql>SELECT OBJECT(o) FROM CustomerBeanTable AS o WHERE o.limit = ?1</ejb-ql>

</query>
----------------

In above query tag use Wrapper class instead of double primitive , I think it may work fine.

Ex:
[<method-param>java.lang.Double</method-param> instead of <method-param>double</method-param> ]

if you find other solution please reply to me.

With Regards,
Lingaiah.S
 
David Chan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now the entity bean is now working

I think there is some problem in the deploytool IDE. In conclusion, if you have added a new finder method, you have to rely on the [Generate default SQL] function to generate sql code. Manually adding the select statement seems not work...

<method-param>double</method-param>
double is OK

Thank you for reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic