Hello,
I'm looking for a way to define a named query manually (programmatically) in a JPA environment but couldn't find any API for doing this.
Any ideas?
Oliver
Hello,
I'm looking for a way to define a named query manually (programmatically) in a JPA environment but couldn't find any API for doing this.
Any ideas?
Oliver
I'm confused, isn't this just a find?
http://www.springframework.org/docs/... g.Object...)
I'm not sure if you can do that. If you find something that says you can, feel free to share. I'm interested, why you need to specify these dynamically anyway?
I need this only for cosmetics :-)
I have a GenericDAO that builds some JQL statements for later execution. I'd like to bind them to a name to be able to get the statement by name.
Another small benefit would probably be, that the statement would get prepared (and syntax would be checked) before it is used the first time, so I would know all errors on application startup.
Oliver
There is no such API. Manage them yourself in a HashMap.I have a GenericDAO that builds some JPQL statements for later execution. I'd like to bind them to a name to be able to get the statement by name.
The JPA spec says nothing about an implementation "preparing" a statement. A PreparedStatement is attached to a Connection, which isnt known til you have a transaction and you invoke it. No syntax checking is required until it is invoked either. There is no benefit to be had.Another small benefit would probably be, that the statement would get prepared (and syntax would be checked) before it is used the first time, so I would know all errors on application startup.
-Andy
DataNucleus - Standardised persistence, multiple datastores
When I said that the statement would get prepared, I didn't mean a PreparedStatement in the sense of a database PREPARE. I'm using Hibernate EntityManager for JPA support - all statements in my orm.xml are being validated on startup, so If there's an error I know it on startup. If you have changed many things in your Domain Layer, you're lucky if you get all errors in one step and do not have to check all possible places.
Obviously executing the query would be one way of testing it. You could run them all at startup. I guess the other way would be to find the code that does the query syntax validation.