Quick question is there a way for me to read a query before running it if I use @NamedNativeQueries syntax.
For example I have query in entity:
Code:
@Entity
@NamedNativeQueries(value = {
@NamedNativeQuery(name = "social.getConnectionUserById2", query = "{$query: { provider : 'FACEBOOK', providerUserId: ':providerUserId'} }", resultSetMapping = "myres")
})
@SqlResultSetMappings(value = {
@SqlResultSetMapping(name="myres", entities = @EntityResult(entityClass = SocialConnection.class))
})
@Table(name = "social_connection" )
public class ...........
Now in DAO I am running it:
Code:
TypedQuery<SocialConnection> namedQuery = entityManager.createNamedQuery("social.getConnectionUserById2", SocialConnection.class);
namedQuery.getSingleResult();
This is all working fine, however what I want is before getSingleResult, I want to be able to parse query string and modify it. Lets say in query I have ':providerId' so I want replace it with my own parameter.
Code:
TypedQuery<SocialConnection> namedQuery = entityManager.createNamedQuery("social.getConnectionUserById2", SocialConnection.class);
String queryStr = namedQuery.getQueryString();
queryStr .....replacing with regex all the parameters
namedQuery.setQueryString(queryStr );
namedQuery.getSingleResult();
is that possible ?