InvalidDataAccessResourceUsageException when updating Audited Entity
adamretter Jul 2, 2011 1:47 PMI have an existing Hibernate project, that I wish to adapt for Envers.
My Hibernate ORM classes are generated from the database schema with Hibernate Tools and, I have added @Audited to the top of each of my Hibernate ORM classes. I realise this is not ideal, however I do want to Audit at the table level, and whilst not all tables need Audtiting, the majority do, and this is a quick way to get started.
However when I try and update the ServiceUser ORM class below, I am getting a InvalidDataAccessResourceUsageException. If I drill down through the stack I see that Envers is trying to execute the SQL select nextval ('hibernate_sequence').
However my sequence is not called 'hibernate sequence' it is called 'service_user_id_seq', and this is specified in a @SequenceGenerator on the id property of the class.
Is this a bug in Envers, or am I doing something wrong?
My class is below, followed by the stack trace. Thanks.
package uk.co.accountablecare.web.orm.generated;
// Generated Jul 2, 2011 7:26:36 PM by Hibernate Tools 3.4.0.CR1
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.SEQUENCE;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.envers.Audited;
/**
* ServiceUser generated by hbm2java
*/
@Entity
@Table(name="service_user"
,schema="public"
)
@Audited public class ServiceUser implements uk.co.accountablecare.web.orm.IStatus,uk.co.accountablecare.web.orm.ISubClient,uk.co.accountablecare.web.orm.IVersioned,java.io.Serializable {
private Integer id;
private Client client;
private ServiceUserBanding serviceUserBanding;
private ServiceUser serviceUser;
private CareAgency careAgency;
private AcwaUser acwaUser;
private Status status;
private Address address;
private Date startDate;
private Date endDate;
private String title;
private String firstName;
private String lastName;
private Date dateOfBirth;
private Date created;
private Set<ServiceUser> serviceUsers = new HashSet<ServiceUser>(0);
private Set<Note> notes = new HashSet<Note>(0);
private Set<ClientServiceUser> clientServiceUsers = new HashSet<ClientServiceUser>(0);
private Set<RfidTag> rfidTags = new HashSet<RfidTag>(0);
private Set<Booking> bookings = new HashSet<Booking>(0);
public ServiceUser() {
}
public ServiceUser(ServiceUserBanding serviceUserBanding, CareAgency careAgency, AcwaUser acwaUser, Status status, Address address, Date startDate, String title, String firstName, String lastName, Date created) {
this.serviceUserBanding = serviceUserBanding;
this.careAgency = careAgency;
this.acwaUser = acwaUser;
this.status = status;
this.address = address;
this.startDate = startDate;
this.title = title;
this.firstName = firstName;
this.lastName = lastName;
this.created = created;
}
public ServiceUser(Client client, ServiceUserBanding serviceUserBanding, ServiceUser serviceUser, CareAgency careAgency, AcwaUser acwaUser, Status status, Address address, Date startDate, Date endDate, String title, String firstName, String lastName, Date dateOfBirth, Date created, Set<ServiceUser> serviceUsers, Set<Note> notes, Set<ClientServiceUser> clientServiceUsers, Set<RfidTag> rfidTags, Set<Booking> bookings) {
this.client = client;
this.serviceUserBanding = serviceUserBanding;
this.serviceUser = serviceUser;
this.careAgency = careAgency;
this.acwaUser = acwaUser;
this.status = status;
this.address = address;
this.startDate = startDate;
this.endDate = endDate;
this.title = title;
this.firstName = firstName;
this.lastName = lastName;
this.dateOfBirth = dateOfBirth;
this.created = created;
this.serviceUsers = serviceUsers;
this.notes = notes;
this.clientServiceUsers = clientServiceUsers;
this.rfidTags = rfidTags;
this.bookings = bookings;
}
@SequenceGenerator(name="generator", sequenceName="service_user_id_seq")@Id @GeneratedValue(strategy=SEQUENCE, generator="generator")
@Column(name="id", unique=true, nullable=false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="client_id")
public Client getClient() {
return this.client;
}
public void setClient(Client client) {
this.client = client;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="banding_id", nullable=false)
public ServiceUserBanding getServiceUserBanding() {
return this.serviceUserBanding;
}
public void setServiceUserBanding(ServiceUserBanding serviceUserBanding) {
this.serviceUserBanding = serviceUserBanding;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="deprecated_by")
public ServiceUser getServiceUser() {
return this.serviceUser;
}
public void setServiceUser(ServiceUser serviceUser) {
this.serviceUser = serviceUser;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="care_agency_id", nullable=false)
public CareAgency getCareAgency() {
return this.careAgency;
}
public void setCareAgency(CareAgency careAgency) {
this.careAgency = careAgency;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="created_by_username", nullable=false)
public AcwaUser getAcwaUser() {
return this.acwaUser;
}
public void setAcwaUser(AcwaUser acwaUser) {
this.acwaUser = acwaUser;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="status_id", nullable=false)
public Status getStatus() {
return this.status;
}
public void setStatus(Status status) {
this.status = status;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="address_id", nullable=false)
public Address getAddress() {
return this.address;
}
public void setAddress(Address address) {
this.address = address;
}
@Temporal(TemporalType.DATE)
@Column(name="start_date", nullable=false, length=13)
public Date getStartDate() {
return this.startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
@Temporal(TemporalType.DATE)
@Column(name="end_date", length=13)
public Date getEndDate() {
return this.endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
@Column(name="title", nullable=false, length=4)
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
@Column(name="first_name", nullable=false, length=50)
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Column(name="last_name", nullable=false, length=50)
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Temporal(TemporalType.DATE)
@Column(name="date_of_birth", length=13)
public Date getDateOfBirth() {
return this.dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name="created", nullable=false, length=29)
public Date getCreated() {
return this.created;
}
public void setCreated(Date created) {
this.created = created;
}
@OneToMany(fetch=FetchType.LAZY, mappedBy="serviceUser")
public Set<ServiceUser> getServiceUsers() {
return this.serviceUsers;
}
public void setServiceUsers(Set<ServiceUser> serviceUsers) {
this.serviceUsers = serviceUsers;
}
@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name="service_user_notes", schema="public", joinColumns = {
@JoinColumn(name="service_user_id", nullable=false, updatable=false) }, inverseJoinColumns = {
@JoinColumn(name="note_id", nullable=false, updatable=false) })
public Set<Note> getNotes() {
return this.notes;
}
public void setNotes(Set<Note> notes) {
this.notes = notes;
}
@OneToMany(fetch=FetchType.LAZY, mappedBy="serviceUser")
public Set<ClientServiceUser> getClientServiceUsers() {
return this.clientServiceUsers;
}
public void setClientServiceUsers(Set<ClientServiceUser> clientServiceUsers) {
this.clientServiceUsers = clientServiceUsers;
}
@OneToMany(fetch=FetchType.LAZY, mappedBy="serviceUser")
public Set<RfidTag> getRfidTags() {
return this.rfidTags;
}
public void setRfidTags(Set<RfidTag> rfidTags) {
this.rfidTags = rfidTags;
}
@OneToMany(fetch=FetchType.LAZY, mappedBy="serviceUser")
public Set<Booking> getBookings() {
return this.bookings;
}
public void setBookings(Set<Booking> bookings) {
this.bookings = bookings;
}
}
And the Stack Trace -
SEVERE: org.springframework.dao.InvalidDataAccessResourceUsageException: could not get next sequence value; SQL [select nextval ('hibernate_sequence')]; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value
javax.faces.el.EvaluationException: org.springframework.dao.InvalidDataAccessResourceUsageException: could not get next sequence value; SQL [select nextval ('hibernate_sequence')]; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value
SEVERE: Servlet.service() for servlet [Blocking Servlet] in context with path [/AccountableCare] threw exception [org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist
Position: 17] with root cause
org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist
Position: 17
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:112)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:105)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:713)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:701)
at org.hibernate.envers.revisioninfo.DefaultRevisionInfoGenerator.saveRevisionData(DefaultRevisionInfoGenerator.java:71)
at org.hibernate.envers.synchronization.AuditProcess.getCurrentRevisionData(AuditProcess.java:126)
at org.hibernate.envers.synchronization.AuditProcess.executeInSession(AuditProcess.java:104)
at org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:152)
at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:543)
at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:216)
at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:571)
at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:250)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:138)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
at uk.co.accountablecare.web.service.impl.ServiceUserServiceImpl$$EnhancerByCGLIB$$24ea0f2b.updateServiceUser(<generated>)
at uk.co.accountablecare.web.view.bean.CareAgencyServiceUsersBean.saveSelectedEntity(CareAgencyServiceUsersBean.java:82)
at uk.co.accountablecare.web.view.bean.AbstractEditableDatatablePopupBean.savePopup(AbstractEditableDatatablePopupBean.java:244)
at uk.co.accountablecare.web.view.bean.AbstractEditableDatatablePopupBean$$FastClassByCGLIB$$3059416d.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
at uk.co.accountablecare.web.view.bean.CareAgencyServiceUsersBean$$EnhancerByCGLIB$$29865e98.savePopup(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:387)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:18)
at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:132)
at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:74)
at com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:31)
at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24)
at com.icesoft.faces.webapp.http.servlet.BasicAdaptingServlet.service(BasicAdaptingServlet.java:16)
at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:53)
at com.icesoft.faces.webapp.http.servlet.SessionVerifier.service(SessionVerifier.java:26)
at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:131)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:56)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)