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.
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?
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.
posted 17 years ago
I am glad things worked out. I hope I was able to help. I am not familiar with EJBX.