-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to disable native SQL or how to control privileges?
PostPosted: Thu Jul 03, 2008 11:06 am 
Newbie

Joined: Tue Jul 01, 2008 4:04 pm
Posts: 2
First of all, is there a way to disable any native SQL code? In particular, I don't want to be able to do session.createSQLQuery("DROP TABLE tablename").

Also, I want to control the select/insert/update/delete privileges that a hibernate session exposes. For example, I would like to map a table to an entity class and use this mapping to only read from the table. Any changes that I make should not be reflected in the database. I don't want to use session.evict(). I have a HibernateUtil class like the hibernate tutorials suggest that exposes the session factory. So I would like to control the access at a higher level (perhaps some simple property in the mapping file that I'm missing?).

I've also tried the <cache usage="read-only"> and am using something called ehcache handler. But I find I can insert records using session.save and I don't want to be able to do this.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 03, 2008 4:07 pm 
Newbie

Joined: Sat May 19, 2007 4:19 pm
Posts: 1
This is a non-hibernate answer to your question, but you could use AspectJ (http://www.eclipse.org/aspectj/) to cause compile errors to be raised if your code contains calls to certain methods. See "Contract Enforcement" of Chapter 1 of the Programming Guide. If you use this approach, you may want to make sure you understand AOP first.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 2:11 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
To prevent calls to Session.createSQLQuery() you can for example wrap the Hibernate Session object in your own Session implementation. All methods that you want to block can simply throw an UnsupportedOperationException. Methods that are allowed are forwarded to the Hibernate Session.

The <cache> settings are for the second-level cache. It has nothing to do with read/write permissions on the database.

Have you tried using the Session.setReadOnly() and/or the Query.setReadOnly() methods? If you wrap the Hibernate session in your own implementation you can for example make all calls to Session.createQuery(), Session.get(), Session.load(), etc. automatically call the setReadOnly() method.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 1:42 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Certianly wrapping the Hibernate Session with your own implementation will eliminate any dangerous methods from being exposed.

I'd like to think you also have some security checks on your database that allows only certain types of things to be performed on your database by your application.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.