Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB 2.0 PROBLEM!!!!  RSS feed

 
Cristian Cardenas
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.
 
Rick Hightower
Author
Ranch Hand
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
Ranch Hand
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!