Depending on your version of Hibernate, you may be able to use Envers to accommodate fine-grained audit logging. This includes the ability to add the 'current user' from a session variable into the given Revision:
@Entity
@RevisionEntity(ExampleListener.class)
public class ExampleRevEntity extends DefaultRevisionEntity {
private String username;
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
}
This integrates with Hibernate nicely through a series of eventListeners, which you can call out in Spring like so:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
...
<property name="eventListeners">
<map>
<entry key="post-insert" value-ref="enversEventListener"/>
<entry key="post-update" value-ref="enversEventListener"/>
<entry key="post-delete" value-ref="enversEventListener"/>
<entry key="pre-collection-update" value-ref="enversEventListener"/>
<entry key="pre-collection-remove" value-ref="enversEventListener"/>
<entry key="post-collection-recreate" value-ref="enversEventListener"/>
</map>
</property>
</bean>
Then you can query for audit revisions through the Envers query api.
After using this on a couple of recent projects, it's my preferred audit technique when using Hibernate.
To answer your question, you can then setup a Hibernate Interceptor or Envers RevisionListener to access the 'current user' by looking it up from the current Spring context:
applicationContext.getBean("currentUser", User.class);
as long as your user is setup as a scoped bean in Spring.