尽管我的休眠sql跟踪清楚地表明一切正常,并且我的数据库确实包含ID = 4的记录,但在调用myMethod()
时仍然出现以下错误:
错误消息堆栈:
DEBUG GenericDaoImpl - Get count of entities of type "UsrProtocol" from db with propertyName=id and propertyValue=6
DEBUG SQL - select count(*) as col_0_0_ from usr_protocol usrp0_ where usrp0_.id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [6]
TRACE BasicExtractor - extracted value ([col_0_0_] : [BIGINT]) - [1]
UsrProtocol id exists:true
DEBUG GenericDaoImpl - An entity of type "UsrProtocol" shall be deleted from db. ID:6
DEBUG GenericDaoImpl - An entity of type "UsrProtocol" has been deleted from db. ID:6
DEBUG GenericDaoImpl - Get count of entities of type "UsrProtocol" from db with propertyName=id and propertyValue=6
DEBUG SQL - delete from user_activity where id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [240]
DEBUG SQL - delete from activity where id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [240]
DEBUG SQL - delete from usr_file where id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [6]
DEBUG SQL - delete from usr_protocol where id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [6]
DEBUG SQL - select count(*) as col_0_0_ from usr_protocol usrp0_ where usrp0_.id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [6]
TRACE BasicExtractor - extracted value ([col_0_0_] : [BIGINT]) - [0]
UsrProtocol id exists:false
resource id :42
DEBUG GenericDaoImpl - An entity of type "Resource" shall be deleted from db. ID:42
DEBUG GenericDaoImpl - An entity of type "Resource" has been deleted from db. ID:42
DEBUG GenericDaoImpl - An entity of type "Usr" shall be updated in db. ID:15
DEBUG SQL - select usrp0_.id as id1_16_0_, usrp0_.comment as comment2_16_0_, usrp0_.protocol_date as protocol3_16_0_, usrp0_.usr_id as usr_id4_16_0_, usrp0_.admin_id as usr_fruu5_16_0_, usrp0_2_.resource_id as resource2_15_0_, case when usrp0_1_.id is not null then 1 when usrp0_2_.id is not null then 2 when usrp0_.id is not null then 0 end as clazz_0_ from usr_protocol usrp0_ left outer join usr_comment usrp0_1_ on usrp0_.id=usrp0_1_.id left outer join usr_file usrp0_2_ on usrp0_.id=usrp0_2_.id where usrp0_.id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [4]
INFO DefaultLoadEventListener - HHH000327: Error performing load command : org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [de.tud.db.entities.UsrProtocol#4]
Aug 17, 2018 12:33:31 PM com.sun.faces.lifecycle.ApplyRequestValuesPhase execute
WARNUNG: #{actionBean[yesButtonAction]}: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [de.tud.db.entities.UsrProtocol#4]
javax.faces.FacesException: #{actionBean[yesButtonAction]}: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [de.tud.db.entities.UsrProtocol#4]
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:117)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:786)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:927)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:69)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter.doFilter(AbstractPreAuthenticatedProcessingFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:68)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:184)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:137)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.orm.hibernate5.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:151)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.AnonymousAuthenticationFERROR TPMExceptionHandler - javax.faces.FacesException: #{actionBean[yesButtonAction]}
UserServiceImpl.java
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
private static org.apache.log4j.Logger log =
Logger.getLogger(UserServiceImpl.class);
@Autowired
private GenericDao<UsrProtocol> UsrProtocolDao;
/*other source code has been omitted*/
@Override
public void myMethod(){
/*other source code has been omitted*/
System.out.println("UsrProtocol id exists:"+UsrProtocolDao.exists(UsrProtocol));
UsrProtocolDao.remove(UsrProtocol);
System.out.println("UsrProtocol id exists:"+UsrProtocolDao.exists(UsrProtocol));
}
}
GenericDaoImpl.java
public class GenericDaoImpl<T> implements GenericDao<T> {
private static org.apache.log4j.Logger log = Logger.getLogger(GenericDaoImpl.class);
private SessionFactory sessionFactory;
private final Class<T> type;
public GenericDaoImpl(final Class<T> type) {
this.type = type;
}
public GenericDaoImpl(final Class<T> type, SessionFactory sessionFactory) {
this.type = type;
this.sessionFactory = sessionFactory;
}
@Override
public boolean exists(final T entity) {
return entity.getId() == null ? false : getCountAllByProperty("id", entity.getId()) > 0;
}
@Override
public boolean remove(final T removeObject) {
log.debug("An entity of type \"" + type.getSimpleName() + "\" shall be deleted from db. ID:" + removeObject.getId());
sessionFactory.getCurrentSession().delete(removeObject);
log.debug("An entity of type \"" + type.getSimpleName() + "\" has been deleted from db. ID:" + removeObject.getId());
return true;
}
//other dao methods such as add, lookup, getAll have been omitted
}
日志跟踪输出:
DEBUG GenericDaoImpl - Get count of entities of type "UsrProtocol" from db with propertyName=id and propertyValue=4
DEBUG SQL - select count(*) as col_0_0_ from usr_protocol usrp0_ where usrp0_.id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [4]
TRACE BasicExtractor - extracted value ([col_0_0_] : [BIGINT]) - [1]
UsrProtocol id exists:true
DEBUG GenericDaoImpl - An entity of type "UsrProtocol" shall be deleted from db. ID:4
DEBUG GenericDaoImpl - An entity of type "UsrProtocol" has been deleted from db. ID:4
DEBUG GenericDaoImpl - Get count of entities of type "UsrProtocol" from db with propertyName=id and propertyValue=4
DEBUG SQL - delete from usr_file where id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [4]
DEBUG SQL - delete from usr_protocol where id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [4]
DEBUG SQL - select count(*) as col_0_0_ from usr_protocol usrp0_ where usrp0_.id=?
TRACE BasicBinder - binding parameter [1] as [INTEGER] - [4]
TRACE BasicExtractor - extracted value ([col_0_0_] : [BIGINT]) - [0]
UsrProtocol id exists:false
UsrProtocol.java
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "usr_protocol")
public abstract class UsrProtocol implements java.io.Serializable {
private Integer id;
private Admin admin;
private Usr usr;
private Date protocolDate;
private String comment;
public UsrProtocol() {
}
public UsrProtocol(final Admin admin, final Usr usr, final Date protocolDate, final String comment) {
this.admin = admin;
this.usr = usr;
this.protocolDate = protocolDate;
this.comment = comment;
}
@Override
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(final Integer id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "admin_id", nullable = false)
public Admin getAdmin() {
return this.admin;
}
public void setAdmin(final Admin admin) {
this.admin = admin;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "usr_id", nullable = false)
public Usr getUsr() {
return this.usr;
}
public void setUsr(final Usr usr) {
this.usr = usr;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "protocol_date", nullable = false, length = 19)
public Date getProtocolDate() {
return this.protocolDate;
}
public void setProtocolDate(final Date protocolDate) {
this.protocolDate = protocolDate;
}
@Column(name = "comment", nullable = false, length = 500)
public String getComment() {
return this.comment;
}
public void setComment(final String comment) {
this.comment = comment;
}
}
UsrFile.java
@Entity
@Table(name = "usr_file")
public class UsrFile extends UsrProtocol implements java.io.Serializable {
private ResourceFile resourceFile;
public UsrFile() {
}
public UsrFile(final ResourceFile resourceFile) {
this.resourceFile = resourceFile;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "resource_id", nullable = false)
public ResourceFile getResourceFile() {
return this.resourceFile;
}
public void setResourceFile(final ResourceFile resourceFile) {
this.resourceFile = resourceFile;
}
}
查询两个表usr_protocol
和usr_file
会返回以下内容:
select * from usr_protocol
select * from usr_file
更新:该问题不仅涉及ID = 4的UsrProtocol,还涉及ID = 5和ID = 6的其他记录!
答案 0 :(得分:0)
您应该检测为什么会产生以下选择:
@echo off
setlocal enabledelayedexpansion
setlocal
for /r %%a in (*.pdf) do (
echo %%~na
)
endlocal
您的实体已被删除,这就是为什么上面的select查询会引发加载问题