How can I resolve this syntax error in JPQL? - jpa

I am fairly new to JPQL and coming from SQL there are some things I still need to get familiar with, so the problem might be caused by that fact.
Working with the CUBA-Framework, I am trying to create a new entity with a JPQL like a form of projection in SQL and I already have succeeded in doing so but now with another case, I got a syntax error. So here is my JPQL:
SELECT NEW
com.example.vet.entity.vet_AnimalInformation(a.cage,0,0,'test',0)
FROM vet_Animals a
This gets transformed internally into what you can see in the exception below and gives me an error:
An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing
[SELECT NEWcom.example.vet.entity.vet_AnimalInformation(tempEntityAlias,0,0,'test',0) FROM vet_Cage tempEntityAlias, vet_Animals a where tempEntityAlias.id = a.cage.id].
[71, 72] The SELECT clause has 'NEWcom.example.vet.entity.vet_AnimalInformation' and '(tempEntityAlias, 0, 0, 'test', 0)' that are not separated by a comma.
Whyever this restructuring occurs, I can live with that, although in comparison to SQL I feel a lack of influence on the statement here :) somehow the constructor is not recognized as such.
What am I doing wrong here?
Thanks in advance!
edit:
Now I wrote my original SELECT clause in the exact way like it is shown in the error message, after it was automatically rewritten and it works! At least I get another error stating that the constructor with those types of parameters could not be found but at least it is recognized as a constructor.
My guess was then that maybe in rewriting the statement then space between NEW and the contructor gets lost but when I leave that out in my original statement I get a totally different error.

Related

Can not add function to mongodb

I don't know when the problem begin. I find that when i create a new function to mongodb, and then run it like this:
db.loadServerScripts();
testFun('xxx');
Two errors will occur:
SyntaxError: missing } after property list src/mongo/shell/db.js:1038
ReferenceError: testFun is not defined (shell):1
But the old functions work fine. And when I delete one old function, and recreate it without anything changed, it also results in the same error above.
The version of mongodb I used is 2.6.10.
I think I have found the answer to this question. The error was cased by some other function. The error message puzzled me , I used to think that it must be an error from the mongo itself. I delete some mongo function written by me, and then the error was missing. Now I can run testFun successfully.

What does this error mean 'The element 'Dependent' in namespace has incomplete content

The element 'Dependent' in namespace 'http://schemas.microsoft.com/ado/2008/09/edm' has incomplete content.
List of possible elements expected: 'PropertyRef' in namespace 'http://schemas.microsoft.com/ado/2008/09/edm'.
I'm using EF4, db first. The error links to an association within the edmx file, unfortunately I am not very experienced with EF Database First (I have previously been using code first) however this error really does not seem to make much sense anyway.
I am guessing a little here but...try regenerating your edmx?

GWT works great in Hosted Mode, and Compiles without error -- but its JS files are buggy

I have no errors show up in either the compilation or the hosted mode process, but the JS that GWT creates contain errors that disallow the proper rendering of the website. How can this happen? Is this a problem with the compiler?
FireBug is giving me nothing, no errors at all.
But I don't know where to go from here or what more information to give you all, since I can't effectively debug JS like this. More fundamentally, I just don't understand why GWT is giving me JS that doesn't work.
EDIT: I didn't really know what Pretty and Detailed meant until now. Thanks for pointing me to this. What I get now is http://i.imgur.com/qUyNb.png.
I'm not sure where to go from here.
EDIT 2: Here is the final image I will post (I promise!): http://i.imgur.com/ZVQVW.png. This is the pretty output. The error reads: "Uncaught com.google.gwt.core.client.JavaScriptException (TypeError): Cannot call method 'isString' of null (anonymous function)."
The resolution to this issue was the realization that isString was not a JNSI method, but instead a method I wrote in a try / catch block. This was the code that tripped me up:
try{something that will create a NullPointerException}
catch(NullPointerException npe){npe.printStackTrace()}
#Luismahou's link above said the following about error-catching in GWT:
Exceptions: try, catch, finally and user-defined exceptions are supported as normal, although Throwable.getStackTrace() is not meaningfully supported in production mode.
Note: Several fundamental exceptions implicitly produced by the Java VM, most notably NullPointerException, StackOverflowError, and OutOfMemoryError, do not occur in production mode as such. Instead, a JavaScriptException is produced for any implicitly generated exceptions. This is because the nature of the underlying JavaScript exception cannot be reliably mapped onto the appropriate Java exception type.
I think what happened is that my try block threw a NullPointerException, which was represented as a JavaScriptException and was uncaught by the catch block. Lesson learned: don't catch NullPointerExceptions, StackOverflowErrors, and OutOfMemoryErrors in GWT.

Entity Framework -- An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.Entity.dll -- Why?

I am trying to use entity framework to make a questionairre. I cannot get the questionairre models to load at all -- each fails with a stackoverflowexception.
I have other models in other EDMX files, and they have worked fine so far.
QuestionEntities qc = new QuestionEntities();
System.Data.Objects.ObjectSet<FormView> qvs = qc.FormViews;
The overflow happens on the second line.
As far as I can tell, they are all set for lazy load, so it should not be attempting to load the entire DB. Just in case it has, I attempted to remove all recursive navigation properties, but it still fails.
The only similar entry I have found is C# - Entity Framework - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
Unfortunately, that one was only solved through repeatedly restarting the EDMX (which I have tried as well).
Any help would be appreciated, thanks
Please look into your generated code, you may have some recursive property definition which may cause the problem. Stack Overflow only occurs in recursive call that ends up in endless loop.
If you post your model and generated code, then it will be easy to find cause of problem.
We did have same problem when there were tables that were recursively included in search, for example consider a tree kind of structure like file system, where directory contains children which are directories, such navigation properties fail to include and results in stack overflow.

How to get an EntityCollection<class> instead of just a class?

I'm trying to convert a one-to-many relationship in entity framework to a many-to-many.
I've done the admin work and generated a database, which seems to be fine but now I'm running through the resulting errors and trying to get the code to compile. Most of it is fine, but one particular change is giving me a headache - I can't figure out the correct syntax. I'm sure I'm being very stupid here.
The original line was:
addedService.CompiledDatabase = context.Databases.OfType<CompiledDatabase>().First();
But addedService.CompiledDatabase is no longer looking for a single instance of CompiledDatabase, it's looking for a collection: an EntityCollection to be precise.
I can't figure out how to get a linq/lambda query that will return a collection of the required type. Assistance gratefully appreciated.
Something like?
addedService.CompiledDatabase.Attach(context.Databases.OfType<CompiledDatabase>());
...if addedService is already in context.