java - How can I tell my database that some changes are made by hibernate and not by other application? -
i'm new in working hibernate , i've got isue. work oracle db , hibernate+maven+netbeans. purpose able changes in database authorized app. making changes sql console or others programs should not possible. made table in database:
create table data( name char(30), day integer, month integer, year integer );
and trigger restricts access on database:
create or replace trigger tri_block before insert or update or delete on data begin if to_number(to_char(sysdate,'hh24')) < 12 or to_number(to_char(sysdate,'hh24')) >= 12 or to_char(sysdate,'dy') in ('sun','sat') raise_application_error (-20000, 'changes can not made'); end if; end;
and hibernateutil.java :
package com.scooby.util; import com.scooby.data; import org.hibernate.sessionfactory; import org.hibernate.cfg.annotationconfiguration; public class hibernateutil { private static final sessionfactory sessionfactory = buildsessionfactory(); private static sessionfactory buildsessionfactory() { try { // create sessionfactory hibernate.cfg.xml return new annotationconfiguration().configure() .addannotatedclass(data.class).buildsessionfactory(); } catch (throwable ex) { // make sure log exception, might swallowed system.err.println("initial sessionfactory creation failed." + ex); throw new exceptionininitializererror(ex); } } public static sessionfactory getsessionfactory() { return sessionfactory; } public static void shutdown() { // close caches , connection pools getsessionfactory().close(); } }
i heard oracle contexts , session in hibernate. can explain me?
trigger not solution preventing unauthorized write access. standard solution create new user app, have neccessary oracle privileges granted/revoked to/from users ensure application allowed write tables.
if not satisfied solution, there sys_context solution, less secure other. offers wider range of features auditing though, requires more work on db side, plus calling stored procedures app well.
Comments
Post a Comment