Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EJB QL RETURNING ONLY THE FIRST RECORD OF THE TABLE

Status
Not open for further replies.

jadeite100

Programmer
May 17, 2006
19
CA
Hi:

I have following EJB QL:
SELECT OBJECT(p) FROM Product p
WHERE p.homeCategory = ?1

which for some weird reason is returning only the first record in the table Product.
In the table product there is a foreign key called categoryId that points to the primary key of the field CategoryId of the table Category.
There is three records in the table Product that contains a foregn key of CategoryId=1, THEREFORE THE ABOVE SQL should return three records from the Product table but the result only returns the first record of the Product table no matter what the value is for the first record of the CategoryId field for the Product Table.

Here are the table structure and data:
Product Table:

ProductId BrandName CategoryId
1 Hush Puppies 2
2 Minnetonka 3
3 Anne klein 1
4 DKNY Mollie 1
5 Bass Kiltie 2

I passed a categoryId of 1 for the above EJB-QL but for some reason, it only returns the first record
of the Product Table. It doesn't seem to matter what the value of the CategoryId. That seems strange.
Is my EJB/QL correct?


Here is the client jsp code that calls the ejb:



<%
Context jndiContext = getInitialContext();
Object objCategory = jndiContext.lookup("CategoryHomeLocal");
CategoryHomeLocal categoryHome = (CategoryHomeLocal)objCategory;
Integer categoryId = new Integer(categoryIdString);
CategoryLocal category = categoryHome.findByPrimaryKey(categoryId);
Collection products = categoryHome.selectProduct(category);
Iterator iterator = products.iterator();
%>

Any hint would be greatly appreciated.
Yours,

Frustrated.
 
Do you really think that code belongs in the jsp?

Anyway, what does the method look like in your ejb.



Christiaan Baes
Belgium

"My old site" - Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top