cancel
Showing results for 
Search instead for 
Did you mean: 

JPA Exception at Constructor Expression: Constructor cannot be determined unambigously

Former Member
0 Kudos

Hello,

I'm facing the following problem and ask you kindly for your help.

I've got entity beans for representing an SQL database. Now I wanted to do a query and fill with it an own data transfer object (DTO) for later use. The query looks somewhat like:              (real names replaced)

SELECT new package.folder.Object(q.attribute1, q.attribute2, q.attribute3)

FROM   Qualification q

WHERE ......

The constructor of the referring object's class looks like:

public Object(String attribute1, EntityObject attribute2, int attribute3){

....

}

The error I get is:

javax.persistence.PersistenceException: The class >>package.folder.Object<< is used in a constructor expression but the constructor cannot be determined unambigously. The arguments types are: java.lang.String;  java.lang.String; int;

I already checked the data types in the DB, the right order in query and cinstructor, I also altered the query with other data types, but nothing changed.

AND there's also only one constructor in the class file. So why does it say the constructor isn't to find "unambigously"?

A strange thing is that the same construct works for another query quite fine. But that other query hasn't been made by me. The only difference is that in the query that works only "native" data types are used as constructor parameters.  Maybe that's it? I cannot use entity objects as parameters?

Does anybody have an idea? I appreciate anything that might help.

Kind regards

Jana


Accepted Solutions (1)

Accepted Solutions (1)

Benny
Product and Topic Expert
Product and Topic Expert
0 Kudos

Obviously that's the case. For some reason the system does not know at compile time what type is behind the object you are using. But it needs to. For this reason it throws an error.

Regards,

Benny

Former Member
0 Kudos

Hi Benny,

you're right. I changed my DTO to one with only primitive Data Types and no error occured anymore. Obviously JPA cannot work with Constructor expressions with Object parameters. Though taht's really a shame...

So thanks for replying!

regards

Jana

Answers (0)