• 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

How to instabntiate the class through EJB QL

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to instantiat the constructor of the class through EJB QL.

I am trying
select new CListing() from CSummaryByDateWeek cdtwk where cdtwk.pk.Id = 1

Here,
CListing is a POJO.
CSummaryByDateWeek is an entity bean mapped to certain table.

when i tried to execute it gives me parse exception. at )

I am wondering is this execution possible in EJBQL?
I got this hint from
http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/queryhql.html section 7.4

Let me know your opinion.

Thanks.
[ November 13, 2008: Message edited by: Rahul Ba ]
 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rahul,

Take a look at JPQL constructor expressions using SELECT NEW. Most good JPQL references should cover it. Here is one: http://edocs.bea.com/kodo/docs41/full/html/ejb3_langref.html.

Regards,
Reza
 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the quick reply...

select new com.cList.CListing(cdtwk.sent) from CSummaryByDateWeek cdtwk where cdtwk.pk.Id = 1


Now my question is how to get the object of current construtor??
i.e CListing(cdtwk.sent)??

I want to return object of this class...

Thanks in advance.
[ November 13, 2008: Message edited by: Rahul Ba ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

unexpected token: )


I'm not sure it will work with the default constructor. What's the point of making new instances if you're not filling it with information taken from the database ? The specification does not clearly say anything about it though.
 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok cool...

I got that, i did correction too.
My next question is

I using this query

select new com.CReport(cdtwk.cStartDate) " +
" from CByDateWeek cdtwk where cdtwk.pk.cId

but it's not finding constructor in class CReport class...

Data type cStartDate in CByDateWeek is Date

I have constructor in CReport class as

public CReport(Date sdate){
...
}

public CReport(Time sdate){
...
}

public CReport(TimeStamp sdate){
...
}

but nothing is working ..it says
Constructor not found exception.......what to more try???
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the complete exception stacktrace.
 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
02:16:41,265 ERROR [PARSER] Unable to locate appropriate constructor on class [com.CReport]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.CReport]

In more detail

Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class com.CReport.

Thanks in advance.
[ November 14, 2008: Message edited by: Rahul Ba ]
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the entity class CByDateWeek including the import statements and annotations used in that class.

While posting, remember to wrap it in a code block using the "Code" button in the message editor window.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Data type cStartDate in CByDateWeek is Date


java.sql.Date ? java.util.Date ?
 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ November 14, 2008: Message edited by: Rahul Ba ]
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The query:

select new com.CReport(cdtwk.cStartDate)



The CReport constructor:

public CReport(String cname,Date sdate){
System.out.println("Hello :"+sdate);
name = cname;
}



You don't have a constructor which accepts just the date. As a result, you see

Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class com.CReport.



You need to fix the query or add a new constructor which accepts just the date.
 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I do have...

select new com.CReport(cdtwk.name,cdtwk.cStartDate) " +
" from CByDateWeek cdtwk where cdtwk.pk.cId

any guess??
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rahul,

If you look at your previous posts which contain the query, the code and the exception, they are completely contradicting each other. It becomes difficult to guess what's wrong. So PostRealCode and the actual exception stacktrace.
 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, Jaikiran

For simpliticity i posted that...Sorry for mis-understanding

Here is my HQL query
select new com.CReport(cdtwk.name,cdtwk.cStartDate) " +
" from CByDateWeek cdtwk where cdtwk.pk.cId



STACK TRACE

02:16:41,265 ERROR [PARSER] Unable to locate appropriate constructor on class [com.CReport]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.CReport]

In more detail

Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class com.CReport.

Thanks in advance.
 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the great help, people.

When I set util.Date in both class, I got the answer.
I am wondering why not for sql.Date?
[ November 14, 2008: Message edited by: Rahul Ba ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your entity class, did you try to set @TemporalType(DATE) to your date field ?
 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to ejb3.
What is use of setting the @TemporalType(DATE) to date field?

Please explain.

Thanks in advance.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rahul Ba:
What is use of setting the @TemporalType(DATE) to date field?



In Java you have a java.sql.Date and a java.util.Date. The java.util.Date includes even the time part (ex: 2008-11-18 16:29:45) whereas the java.sql.Date does not include the time part (ex: 2008-11-18).

The @Temporal annotation is used to specify what level of precision you want with the Date type field. i.e. It allows you to specify whether you are interested only in the DATE part or only with the TIME part or both the date and the time (TIMESTAMP). So a @Temporal(TemporalType.DATE) tells that you are only interested in the Date part of the data stored in the column corresponding to this field.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic