Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

EJB 2.0 PROBLEM!!!!

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an Address table related with Customer by a reference (Addres(customer_pk) -->Customer(customer_pk) ).
So I have an AddressEJB entity bean which have a field customer (getCustomer, setCustomer) which type CustomerLocal.
And I have a finder with the following EJB-QL associated:
"SELECT OBJECT (a) FROM AddressEJB as a WHERE a.customerPk = ?1"
The customerPk field doesn't exist in the AddressEJB entity
My question is:
Is the EJB-QL sentence valid?
How must I to make the sentence works?
Thanks a lot.
Cristian.
 
Author
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to see more code to answer this question...
However...
Let's assume the following:
1) Customer does have a cmp field called customerPk
2) you set up the relationship between Customer and Address correctly
3) Address does *not* have a cmp field called customerPK
Then the EJB QL could be written like this:
SELECT OBJECT (a) FROM AddressEJB as a WHERE a.customer.customerPk = ?1
Questions for you:
Does AddressEJB have a cmp field called customerPk?
Does Customer have a cmp field called customerPk?
Which app server are you using?
What error message are you getting?

Go through this tutorial...
http://www.rickhightower.com/ejbcmpcmrtut.html
and this
http://java-tools.eblox.com/index.php?ResinCMPCMRXDocletTutorial
 
Cristian Cardenas
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answers:
Does AddressEJB have a cmp field called customerPk?
no
Does Customer have a cmp field called customerPk?
yes
Which app server are you using?
weblogic 6.1 sp1
What error message are you getting?
Invalid Identifier in EJB QL expression: JOIN calculation. Cannot find RDBMSBean for cmpfield: customerPk
I'm using EJBX to generate de Entities and it generate bad EJB-QL queries, like the one we're discussing.
Forte and EJBX don't generate a cmp field when it's a foreign key (cmr field), except that it's a primary key also. So, the query must be like:
SELECT OBJECT (a) FROM AddressEJB as a WHERE a.customer.customerPk = ?1
A query like this doesn't need a join between the tables being used. Will the SQL generated by the container at deploy time use a join or there is a optimization?
In other words:
SELECT OBJECT (a) FROM AddressEJB as a WHERE a.customer.customerPk = ?1
seems to the following SQL query
SELECT * FROM Address a, Customer c WHERE a.customerPk=c.customerPk and c.customerPk=1
the optimized query can be:
SELECT * FROM Address a WHERE a.customerPk=1
Thanks.
Cristian.
 
Rick Hightower
Author
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am glad things worked out. I hope I was able to help. I am not familiar with EJBX.
 
Fire me boy! Cool, soothing, shameless self promotion:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic