David,
Thanks much for your reply.
Quote:
When using composite keys the key generation needs to be assigned.
Ok, does this mean that i have to use some kind of generator for composite keys and i cannot assign them based on some logic i have.
Quote:
The interceptor can be implemented with the unused mthods as stubs.
Most IDEs will build the class for you so you only need to add a few lines of code.
Ok, so there are two ways i can set the interceptor:-
Code:
SessionFactory.openSession(myInterceptor),
Configuration.setInterceptor(myInterceptor)
Assume that
Code:
myInterceptor
implements
Code:
Interceptor
.
Now when i do this and myInterceptor does not implement/does not give the right return values for the other methods like ...
Code:
boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
Called before an object is saved.
Quote:
The above is from net.sf.hibernate.Interceptor
What will happen ? will these methods still be called by hibernate ? I do acknowledge my complete ingorance of the Interceptor.
I use Eclipse and for
Code:
onSave()
it gives me this stub:-
Code:
/* (non-Javadoc)
* @see net.sf.hibernate.Interceptor#onSave(java.lang.Object, java.io.Serializable, java.lang.Object[], java.lang.String[], net.sf.hibernate.type.Type[])
*/
public boolean [quote]onSave[/quote](
Object arg0,
Serializable arg1,
Object[] arg2,
String[] arg3,
Type[] arg4)
throws CallbackException {
// TODO Auto-generated method stub
return false;
}
Here is what the javadoc says for this method :-
Code:
onSave
public boolean onSave(Object entity,
Serializable id,
Object[] state,
String[] propertyNames,
Type[] types)
throws CallbackExceptionCalled before an object is saved. The interceptor may modify the state, which will be used for the SQL INSERT and propagated to the persistent object.
Returns:true if the user modified the state in any way. CallbackException
I frankly do not understand wether my stub for the above method is ok or not.
As far as i can see, all i need to implement only
Code:
isUnsaved()
method.
Thus, any examples, usage documentation will be highly appreciated.(I did read the manual though)
Also now David, comimg back to the First question, let's say i implement a Interceptor, will i be able to now use it for the composite objects as well ?
Another question.
Quote:
Assume here that all the objects in the statements below have auto generated keys.
What about a cacade where i may have the parent object in the database and the child objects may or may not be already in the database, that is, some new children which need a save and some children from the database which need a update? Will the Interceptor work then.
What if the child has a one to many with another child, which has a one to many with another child. and the children at ay level, can be, some new children which need a save and some children from the database which need a update.
Please do point out if i am not making things clear.
To sum up there are three questions:-
1) If i stub Interceptor methods can there be any potential negative side effects.
2) Can i use a Interceptor with composite keys, where i have some application logic fill up the keys.
3) Can i use a Interceptor with a n level cascade collection, where some objects are for save and some for update ? SaveOrUpdate();
Thanks for all the help.
Again, if i am being unclear do point out the same.
Regards
Suchak Jani