Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

EJB QL question

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning Entity Beans and EJB QL and have come across the following dilemna. I have a legacy relational db some of whose columns are Java type java.sql.Date. I created an Entity Bean to manage persistence with this table. I created a ejbSelectMethod with the query SELECT OBJECT(b) FROM Booking AS b WHERE b.fld1 = ?1 AND b.fld2 = ?2 AND bl.fld3 = ?3. fld1 and fld2 are strings, but fld3 is type java.sql.Date, and reading Monson-Haefel's Enterprise JavaBeans 4th Ed., I learned that you can't use java.util.Date/java.sql.Date objects in equality comparisons, rather, you must compare dates in long/millis form. I tried defining a CMP field of type long in my Entity bean, but my EJB container won't let me deploy it because the CMP field doesn't have a counterpart in the db table (my EJB container has a vendor-specific deployment descriptor for mapping CMP fields to db columns). Monson-Haefel says you must persist the date in long form rather than Date form, but modifying the definition of my legacy table is not an option. Is there something I can do with my Entity bean CMP fields and/or methods that will allow me to the EJB QL query indicated (with "fld3= ?3" being a comparison of longs)?
 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the book mentions, you would not be able to compare dates for an equality. You should compare them for a range; like a date between something and something else. Your EJB QL should would need to be adjusted accordingly.

And, could you please edit your message to add some line breaks in between? It is really difficult to read at the moment.
 
Randy Gibbons
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Annie. Trying a range occurred to me too, but I don't see which operator would do that, since Monson-Haefel explictly says it is not possible to use any comparison operator (=, >, >=, etc.) to compare Date CMP fields (which is what I have) with find/select method input parameters or literal values. If you see something I don't, let me know!

I also have a more general question. As I said in my original posting, my EJB container won't allow CMP fields that don't map to a specific column in the data store. Is that spec-conformant and the way things are, or a limitation in my EJB container (SAP's J2EE Engine). It strikes me as contradicting the idea of the Entity bean as an "abstract persistent schema" that can be used (so I thought) in conjunction with many underlying date stores.
 
Are you okay? You look a little big. Maybe this tiny ad will help:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic