Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

entityManager executing statements on system tables?

 
Pat Peg
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I need to do is execute 'ALTER USER username ACCOUNT LOCK' but all I find under entityManager is executeQueries or NativeQueries...I tried executeNativeQuery and while it did not throw any exceptions (after I granted the right permissions to the account) it also did not lock the user...I suspect because I am not really doing a query. Is there a way to execute a statement or how should I do this?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
em.createNativeQuery("ALTER USER username ACCOUNT LOCK").executeUpdate();

This should work. Ensure you are not in a transaction, or if you are commit the transaction.
 
Pat Peg
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James,

First of all; thank you.

I am getting a COMMIT is not allowed in a subordinate session so I suppose I am in a transaction but I am not sure what to do to correct this. This is what I have done.



I am getting this error


javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:60)
at com.bah.englink.ejb.pm.UserProfileManager$$M$d57c1113.switchUserStatus(UserProfileManager.java:2204)
at com.bah.englink.ejb.pm.UserProfileManager$$A$d57c1113.switchUserStatus(<generated>)
at com.bah.englink.ejb.pm.UserProfileManager.switchUserStatus(UserProfileManager.java:2222)
at com.bah.englink.ejb.pm.UserProfileManager_n071r6_Impl.switchUserStatus(UserProfileManager_n071r6_Impl.java:50001)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic