Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Date type in an EJB Query Language

Posted on 2008-10-07
1
Medium Priority
?
1,832 Views
Last Modified: 2013-12-14
I am developing an application in NetBeans thats uses the built in database server (apache derby), i've used the IDE to generate entity classes refelecting tables in my database. The IDE has also created a persistance unit and an entity manager, i am trying to run an EJB Query on a table in the database but i am having some syntactical difficulties which i am having trouble resolving.

This is the EJB QL:

SELECT m FROM Measurement m WHERE m.measurementDateofbooking = '07.10.2008'

This is the Measurement Table Structure in the database:

MEASUREMENT                             Data Type
=====================================
measurement_id                           Auto Gen Int PK
measurement_customer_id          Int FK
measurement_dateofbooking       Date
measurement_timeofbooking       Time
measurement_completed             Char

This is a relevant snippet of the measurement Entity Class: (See Code Snippet)

This is the exception i recieve:

Exception Description: The object [07.10.2008], of class [class java.lang.String], from mapping [oracle.toplink.essentials.mappings.DirectToFieldMapping[measurementDateofbooking-->MEASUREMENT."measurement_dateofbooking"]] with descriptor [RelationalDescriptor(mk_carpets_alpha_entity_classes.Measurement --> [DatabaseTable(MEASUREMENT)])], could not be converted to [class java.sql.Date].

Exception in thread "AWT-EventQueue-0" Local Exception Stack:

Exception [TOPLINK-3002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.ConversionException

Exception Description: The object [07.10.2008], of class [class java.lang.String], from mapping [oracle.toplink.essentials.mappings.DirectToFieldMapping[measurementDateofbooking-->MEASUREMENT."measurement_dateofbooking"]] with descriptor [RelationalDescriptor(mk_carpets_alpha_entity_classes.Measurement --> [DatabaseTable(MEASUREMENT)])], could not be converted to [class java.sql.Date].

        at oracle.toplink.essentials.exceptions.ConversionException.incorrectDateFormat(ConversionException.java:119)
        at oracle.toplink.essentials.internal.helper.Helper.dateFromString(Helper.java:747)


After looking at the exception i thought it might be the format of the date, but i tried the same date in the database sql command ('07.10.2008') and it retrieved the results fine. I even tried changing my EJB Q to this: SELECT m FROM Measurement m WHERE m.measurementDateofbooking = new Date(2008,10,7)
and it still didnt work.
package mk_carpets_alpha_entity_classes;
 
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
 
/**
 *
 * @author ______
 */
@Entity
@Table(name = "MEASUREMENT")
@NamedQueries({@NamedQuery(name = "Measurement.findByMeasurementId", query = "SELECT m FROM Measurement m WHERE m.measurementId = :measurementId"), @NamedQuery(name = "Measurement.findByMeasurementDateofbooking", query = "SELECT m FROM Measurement m WHERE m.measurementDateofbooking = :measurementDateofbooking"), @NamedQuery(name = "Measurement.findByMeasurementTimeofbooking", query = "SELECT m FROM Measurement m WHERE m.measurementTimeofbooking = :measurementTimeofbooking"), @NamedQuery(name = "Measurement.findByMeasurementCompleted", query = "SELECT m FROM Measurement m WHERE m.measurementCompleted = :measurementCompleted")})
public class Measurement implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "\"measurement_id\"", nullable = false)
    private Integer measurementId;
    @Column(name = "\"measurement_dateofbooking\"", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date measurementDateofbooking;
    @Column(name = "\"measurement_timeofbooking\"", nullable = false)
    @Temporal(TemporalType.TIME)
    private Date measurementTimeofbooking;
    @Column(name = "\"measurement_completed\"")
    private Character measurementCompleted;
    @JoinColumn(name = "\"measurement_customer_id\"", referencedColumnName = "\"customer_id\"")
    @ManyToOne
    private Customer measurementCustomerId;

Open in new window

0
Comment
Question by:awax187
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
awax187 earned 0 total points
ID: 22663974
ok never mind ive solved the problem. The date in the EJB Query should have been in the format, 'yyyy-mm-dd' i was writing it in the wrong form. Hope somebody finds this useful.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question