• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

EJB QL question

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic