• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

retriving null object with another value object through expressions

 
Mohammad Noor Najdawi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

kindly i am working on retrieving data from the database; i want to get from indexStatusTypeId column the row(object) when it equal to 1 or empty (null), but when i ran the following code it just retrive objects equal to 1, it does not retrieve the null ones

Expression exp = new ExpressionBuilder();
Expression expTwo = new ExpressionBuilder();
exp = exp.get("indexStatusType").get("indexStatusTypeId").notEqual(2);
expTwo = expTwo.get("indexStatusType").get("indexStatusTypeId").notEqual(3).and(exp);

thank you

 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Mohammad .

What product are you using to talk to the database?
 
Mohammad Noor Najdawi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am working on eclipselink with a GeneralDAO API
 
Mohammad Noor Najdawi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GeneralDAO is an API used localy in my place(work)
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have moved this post to our Object Relational Mapping forum for you.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see a test for null, just a bunch of not equals tests. They are not the same thing.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The get("indexStatusType") call implies a join, in the database this will filter out null results.

To avoid this you must use an outer join in the database, to do this use,

getAllowingNull("indexStatusType")

 
Mohammad Noor Najdawi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
the indexStatusType is object in table has indexStatusTypeId of type long, and this attribute in database has the following values: 1,2,3, empty(null) i had write the previous code supposing to get notEqual(2) and notEqual(3), but i got only the equal (1) result.

i am also trying to write the following
Expression exp;
ExpressionBuilder builder = new ExpressionBuilder();
Expression expTwo;
ExpressionBuilder builderTwo = new ExpressionBuilder();
exp = builder.get("indexStatusType").isNull();
expTwo = builderTwo.get("indexStatusType").get("indexStatusTypeId").equal(1).or(exp);

and then get the result of expression expTow, but also i get the only the result of equal(1). although when i get the equal(null) or isNull() only in a get statement it work, but if i or it with another expression it return the another value not the null one.

i think the problem in or, may be the or here between object of type IndexStatusType and indexStatusTypeId which is long
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic