aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB QL: Comparing a Dependent Value CMP Field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB QL: Comparing a Dependent Value CMP Field" Watch "EJB QL: Comparing a Dependent Value CMP Field" New topic
Author

EJB QL: Comparing a Dependent Value CMP Field

Skripi Mayer
Greenhorn

Joined: Jun 15, 2004
Posts: 10
Hi,

I have a Serializeable Object in a CMP(2.0) Entity Bean.
I'm unable to define a proper QL, that is accepted by the Sun J2EE 1.3.1 RI:
---------- EJB QL ----------
SELECT OBJECT (perm)
FROM PermissionBeanSchema AS perm
WHERE perm.permission = ?1
---------- EJB QL ----------

As far as I understand, I have fullfilled all requirements:
- class Permission is serializable and implements an equals method
- field permission is declared as CMP field inside the Bean.
- the parameter in findByPermission(Parameter) is the same Object
class as the persistence field.

But still the EQL Compiler complains about '(perm.permission = ?1)'.

Any Ideas ??

----------- Java example code -----------
public abstract class PermissionBean implements EntityBean{

public abstract void setPermission(Permission perm);
public abstract Permission getPermission();

[...]
}

public interface PermissionHomeLocal extends EJBLocalHome {

[...]

public PermissionLocal findByPermission(Permission permission)
throws FinderException;

}

public class Permission implements Serializable {
public final static Permission CREATE_USER = new Permission("Create User", "Allows User Creation");

final private String name;
final private String description;


private Permission (final String name, final String description){
this.name = name;
this.description = description;
}

public String getName() { return this.name; }

public String getDescription() { return this.description; }

public boolean equals(Object obj) {
if (obj instanceof Permission) {
Permission perm = (Permission) obj;
return this.name.equals(perm.getName());
}
return false;
}
}
[ June 19, 2004: Message edited by: Skripi Mayer ]
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
What exception are you getting? In deploying or running?

Something looks kind of weird in your code.
In the following query

SELECT OBJECT (perm)
FROM PermissionBeanSchema AS perm
WHERE perm.permission = ?1


The field permission must be an abstract primitive type field in your bean for you to compare it this way. This query doesn't make sense to me if permission is an object...!?

Your bean class seems kind of weird to. In the following methods


Is Permission a LocalInterface? Because if it's not, it should be.
Usually, you'd have something like this for the above methods.


Note the Local suffix that is the usual suffix for Local Interfaces.


Leandro Melo
SCJP 1.4, SCWCD 1.4
Skripi Mayer
Greenhorn

Joined: Jun 15, 2004
Posts: 10
Thank you ltcmelo,

I just thought, that I could compare any valid CMP-field.

11.2.10 Equality semantics
EJB QL only permits like type values to be compared. There is one exception to this rule: it is valid to
compare exact numeric values and approximate numeric values (the rules of Java numeric promotion
define the required type conversion). Conditional expressions attempting to compare non-like type values
are disallowed except for this numeric case.
With the exception of null values as described above, value comparisons should observe the Java language
semantics. For example, cmp-fields defined in terms of numeric primitive types cannot be
assumed to have NULL values. (If the Bean Provider wishes to allow null values for cmp-fields, he or
she should specify those cmp-fields to have the equivalent Java object types instead of primitive types,
e.g., Integer rather than int.) The comparison of strings should not be affected by their representation
in the persistent store (e.g., with regard to padding, etc.) Two strings are equal if and only if they
contain the same sequence of characters. This is different from SQL.
Two entity objects of the same abstract schema type are equal if and only if they have the same primary
key value.


What did I get wrong ?

I have looked all over the place, can you tell me, where I can find this resctriction ? I just found, that Objects need to be of equal type.

Permission is an implemented class and a valid CMP-Field. I was just unable to find any restriction on the comparisions.

The Permission field I use currently is a valid, serializable class.
Where can I find further information on those comparison features of EJB QL ?
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
First, i'd like to correct myself when i said

The field permission must be an abstract primitive type field in your bean


As you noticed you might be a String or Integer, for example. Anyway, what i wanted to say is that it looks like you're trying to compare the object itself and not it's fields.

Second, althoug i'm also a beginner here, it will be hard for anyone to try to help you, if you don't say what error you're getting
 
jQuery in Action, 2nd edition
 
subject: EJB QL: Comparing a Dependent Value CMP Field