aspose file tools*
The moose likes Object Relational Mapping and the fly likes Issues executing a query which makes use of a constructor expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Issues executing a query which makes use of a constructor expression" Watch "Issues executing a query which makes use of a constructor expression" New topic
Author

Issues executing a query which makes use of a constructor expression

Danny Matthews
Greenhorn

Joined: Dec 14, 2009
Posts: 5
Hi,

I'm attempting to make use of a query with constructor expression within my application but am having problems. I've pasted the stack trace obtained when trying to deploy the application, the offending query and the constructor expression class below:







The discriminator column is of type DiscriminatorType.STRING.

I'm thoroughly confused as to what's going on...

Any help would be appreciated.

Thanks,

Danny
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
Few Queries:

1) What is this Type function??
2) You mentioned about discriminator column... Where is the inheritance coming into picture..
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10040
    
163

Firstly, a NullPointerException in the stacktrace is always a sign of a bug. So you'll have to check the Hibernate JIRAs if this one is already reported. If not, then you might want to report this issue.

Secondly, your entity class:


doesn't have an default no-arg constructor. The spec states that:


EJB3 Persistence Spec, Section 2.1 wrote:The entity class must have a no-arg constructor. The entity class may have other constructors as well. The no-arg constructor must be public or protected.


By the way how do you mark this class as an entity? I don't see the @Entity in your code.

[My Blog] [JavaRanch Journal]
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
Jaikiran, @Entity is not requried in definition of SensorDataContainer class as this class is not entity. It has been used only for storing persistence values from database. It's a only a temproral storage.

As SensorDataContainer is not entity so no need to providing default constructor. It will work fine without default constructor.

Danny,

Only problem is with your named query. I think your named query should like

@NamedQuery(name = "dateRangedQuery",
query = "SELECT new entities.SensorDataContainer(d, d.type) " +
"FROM SensorData AS d " +
"WHERE d.sampleTime BETWEEN :fromDate AND :toDate " +
"AND Type(d) IN (:sensorList)"
)

As you have provided Type(d)) in named queries, it means that you are tying to typecase sensorData object d in some different object Type. Which is thrwoing exception. In place of this you need to use d.<property name which is defined in sensorData object>

I have tried below named query
@NamedQuery(name="dateRangedQuery", query = "SELECT new com.sunil.SensorDataContainer(d, d.type) " +
"FROM SensorData AS d ")

and its working fine. I am able to pull data from database. I have removed your date range condition for simplification.

Hope this will solve your problem

-Sunil
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
and also take please relook in below red blocked portion of named query

@NamedQuery(name = "dateRangedQuery",
query = "SELECT new entities.SensorDataContainer(d, d.type) " +
"FROM SensorData AS d " +
"WHERE d.sampleTime BETWEEN :fromDate AND :toDate " +
"AND Type(d) IN (:sensorList)")

Modify this also as per your requirment.

-Sunil
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10040
    
163

xsunil kumar wrote:Jaikiran, @Entity is not requried in definition of SensorDataContainer class as this class is not entity. It has been used only for storing persistence values from database. It's a only a temproral storage.

As SensorDataContainer is not entity so no need to providing default constructor. It will work fine without default constructor.


Ah, ok! I did not pay attention to that part.
Danny Matthews
Greenhorn

Joined: Dec 14, 2009
Posts: 5
Thanks for the prompt replies .

It's good to know what's causing the problem. Thanks!

The problem I have now is that I need to refer to the entity discriminatory column within the query and the only way I know to achieve this is using the Type() function...

Do you have any ideas of how I could refer to the discriminator column within the query?

Many thanks for the help so far .

Danny
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issues executing a query which makes use of a constructor expression