• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB QL: Comparing a Dependent Value CMP Field

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Skripi Mayer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic