java - Why does Hibernate persist an object of its own initiative? -


i have see bottom of that. here's brief abstract: have configuration model object has configuration settings along username , password. of course, password encrypted , have decrypt use it. pragmatically, load configuration object hibernate (the password encypted), password, decrypt it, , set password attribute newly evaluated plaintext (i use setter mothod). please note never store configuration object again. weird result found configurations table updated password plaintext in db! guess hibernate caching system has role in mystery, must understand why , how.

the details in following:

i use spring framework, version 3.1.2 release

servlet.xml

    <!-- hibernate -->     <dependency>         <groupid>org.hibernate</groupid>         <artifactid>hibernate-core</artifactid>         <version>4.0.0.final</version>     </dependency> 

service

@service("configurationmanager") public class configurationmanager {      //attributes , blah blah      public configuration loadconfiguration()     {         //the configuration's password attribute encrypted in db         configuration configuration = configurationdao.load();         if(configuration!=null)         {             //...to use password must decrypt             if(!(configuration.getpassword()==null || configuration.getpassword().isempty()))             {                                    string encryptedtext = configuration.getpassword();                 string decryptedtext = credentialsmanager.decrypt(encryptedtext);                 //after decrypting password, set configuration's password attribute plaintext password                 //i'll never ever store configuration obj newly set password.                 configuration.setpassword(decryptedtext);             }         }         return configuration;     }    } 

(maybe useless) clue: notice hibernate behaviour since started use aop different purposes. can't see clear connection between 2 things, report anyway it. included these libs in project:

    <dependency>         <groupid>org.aspectj</groupid>         <artifactid>aspectjrt</artifactid>         <version>1.7.2</version>     </dependency>     <dependency>         <groupid>org.aspectj</groupid>         <artifactid>aspectjweaver</artifactid>         <version>1.7.2</version>     </dependency>    

when load object hibernate, instance bound session loaded with, , keep track of changes it. when session flushed (calling appropriate method or internally due flushmode selection on session behaviour) changes synchronized db.

either not change object loaded , store unencrypted password in e.g. nonpersistent attribute, or call evict detach session.

edit: background info, see hibernate docs, , in particular section 11.1 - hibernate object states - can see there object loaded session in persisted state, , changes persisted when work unit completes (i.e. session flushed.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -