有时我在Web应用程序项目中遇到了问题。当我尝试更新Construction Member实体时,Construction Order Id从旧值更改为null。
同时,表“ Construction Member”中没有带有“ Construction Order”的外键,只有Construction Team拥有带有“ Construction Order”的外键
(“施工顺序”>“施工团队”>“施工成员”)
尽管我没有调用任何方法来更新“构造顺序”,但我只使用“构造成员”的数据,并且对这些实体中的每个@ManyToOne都使用了“ updatable = false”,以避免不必要的数据更改。但是错误仍然出现。
注意:当我尝试重新启动服务器时,该错误不存在,并且当我在Web应用程序上处理大量数据时,该错误再次出现,这迫使我再次重新启动服务器以继续使用Web App
-这是我的错误
c.l.n.c.ConstructionMemberController.update - Error when updating constructionMember.
org.springframework.orm.jpa.JpaSystemException: identifier of an instance of com.logsik.nguyencons.domain.ConstructionOrder was altered from 1 to null; nested exception is org.hibernate.HibernateException: identifier of an instance of com.logsik.nguyencons.domain.ConstructionOrder was altered from 1 to null
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:333)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:521)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy122.save(Unknown Source)
at com.logsik.nguyencons.controller.ConstructionMemberController.update(ConstructionMemberController.java:55)
at com.logsik.nguyencons.controller.ConstructionMemberController$$FastClassBySpringCGLIB$$8b6ed292.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:69)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.logsik.nguyencons.controller.ConstructionMemberController$$EnhancerBySpringCGLIB$$63c589cb.update(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)
at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:206)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.doFilter(OAuth2AuthenticationProcessingFilter.java:176)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
at com.logsik.nguyencons.config.SimpleCorsFilter.doFilter(SimpleCorsFilter.java:43)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:541)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:481)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:564)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:199)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.hibernate.HibernateException: identifier of an instance of com.logsik.nguyencons.domain.ConstructionOrder was altered from 1 to null
at org.hibernate.event.internal.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:64)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:175)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:135)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:216)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:85)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:38)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:465)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2963)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2339)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:147)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:61)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
... 128 common frames omitted
-这是我的数据库。
建筑工人
CREATE TABLE `construction_member` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NULL DEFAULT NULL,
`construction_team_id` bigint(20) NULL DEFAULT NULL,
`work_on` varchar(255) NULL DEFAULT NULL,
`note` longtext NULL,
PRIMARY KEY (`id`) ,
CONSTRAINT `fk_constructionMember_constructionTeam` FOREIGN KEY (`construction_team_id`) REFERENCES `nguyencons`.`construction_team` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
INDEX `fk_constructionMember_constructionTeam` (`construction_team_id` ASC) USING BTREE
)
ENGINE = InnoDB
AVG_ROW_LENGTH = 0
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci
KEY_BLOCK_SIZE = 0
MAX_ROWS = 0
MIN_ROWS = 0
ROW_FORMAT = Dynamic
STATS_SAMPLE_PAGES = 0;
施工队
CREATE TABLE `construction_team` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`construction_order_id` bigint(20) NULL DEFAULT NULL,
`team_name` varchar(255) NULL DEFAULT NULL,
`note` longtext NULL,
PRIMARY KEY (`id`) ,
CONSTRAINT `fk_constructionTeam_constructionOrder` FOREIGN KEY (`construction_order_id`) REFERENCES `nguyencons`.`construction_order` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
INDEX `fk_constructionTeam_constructionOrder` (`construction_order_id` ASC) USING BTREE
)
ENGINE = InnoDB
AVG_ROW_LENGTH = 0
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci
KEY_BLOCK_SIZE = 0
MAX_ROWS = 0
MIN_ROWS = 0
ROW_FORMAT = Dynamic
STATS_SAMPLE_PAGES = 0;
施工订单
CREATE TABLE `construction_order` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`project_location_id` bigint(20) NULL DEFAULT NULL,
`start_work_date` date NULL DEFAULT NULL,
`end_work_date` date NULL DEFAULT NULL,
`number_of_completed_day` int(11) NOT NULL DEFAULT 0,
`status` varchar(255) NULL DEFAULT NULL,
`note` longtext NULL,
PRIMARY KEY (`id`) ,
CONSTRAINT `fk_constructionOrder_projectLocation` FOREIGN KEY (`project_location_id`) REFERENCES `nguyencons`.`project_location` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
INDEX `fk_constructionOrder_projectLocation` (`project_location_id` ASC) USING BTREE
)
ENGINE = InnoDB
AVG_ROW_LENGTH = 0
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci
KEY_BLOCK_SIZE = 0
MAX_ROWS = 0
MIN_ROWS = 0
ROW_FORMAT = Dynamic
STATS_SAMPLE_PAGES = 0;
-这是我的域
施工顺序。
@Entity(name="construction_order")
public class ConstructionOrder implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Access(AccessType.PROPERTY)
private Long id;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name= "project_location_id", updatable=false)
private ProjectLocation projectLocation;
@Column
@Temporal(TemporalType.DATE)
private Date startWorkDate;
@Column
@Temporal(TemporalType.DATE)
private Date endWorkDate;
@Column
private Integer numberOfCompletedDay;
@Column
@Enumerated(EnumType.STRING)
private ConstructionOrderStatus status;
@Lob
@Column(columnDefinition="longtext")
private String note;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public ProjectLocation getProjectLocation() {
return projectLocation;
}
public void setProjectLocation(ProjectLocation projectLocation) {
this.projectLocation = projectLocation;
}
public Date getStartWorkDate() {
return startWorkDate;
}
public void setStartWorkDate(Date startWorkDate) {
this.startWorkDate = startWorkDate;
}
public Date getEndWorkDate() {
return endWorkDate;
}
public void setEndWorkDate(Date endWorkDate) {
this.endWorkDate = endWorkDate;
}
public Integer getNumberOfCompletedDay() {
return numberOfCompletedDay;
}
public void setNumberOfCompletedDay(Integer numberOfCompletedDay) {
this.numberOfCompletedDay = numberOfCompletedDay;
}
public ConstructionOrderStatus getStatus() {
return status;
}
public void setStatus(ConstructionOrderStatus status) {
this.status = status;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
施工队
@Entity(name = "construction_team")
public class ConstructionTeam implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Access(AccessType.PROPERTY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "construction_order_id" , updatable = false)
private ConstructionOrder constructionOrder;
@Column
private String teamName;
@Lob
@Column(columnDefinition = "longtext")
private String note;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public ConstructionOrder getConstructionOrder() {
return constructionOrder;
}
public void setConstructionOrder(ConstructionOrder constructionOrder) {
this.constructionOrder = constructionOrder;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
建设成员
@Entity(name = "construction_member")
public class ConstructionMember implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Access(AccessType.PROPERTY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", updatable=false)
private User user;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "construction_team_id", updatable=false)
private ConstructionTeam constructionTeam;
@Column
private String workOn;
@Lob
@Column(columnDefinition = "longtext")
private String note;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public ConstructionTeam getConstructionTeam() {
return constructionTeam;
}
public void setConstructionTeam(ConstructionTeam constructionTeam) {
this.constructionTeam = constructionTeam;
}
public String getWorkOn() {
return workOn;
}
public void setWorkOn(String workOn) {
this.workOn = workOn;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
-这是我的Construction Memeber Controller¬¬(更新)
@RequestMapping(value = "/constructionMember/update", method = RequestMethod.POST)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResult update(@RequestBody ConstructionMember constructionMember) {
try {
ConstructionMember source = constructionMemberRepository.findOne(constructionMember.getId());
ConstructionMember updatedConstructionMember = constructionMemberRepository.save(dtoConverter.fillConstructionMemberForm(source, constructionMember));
return new RestResult(updatedConstructionMember);
} catch (Exception e) {
LOGGER.error("Error when updating constructionMember.", e);
return new RestResult(true, MESSAGE_CANNOT_SAVE);
}
}
这是我的存储库
public interface ConstructionMemberRepository extends
BaseRepository<ConstructionMember, Long> {
@EntityGraph(attributePaths = {"constructionTeam","user"})
Page<ConstructionMember> findById(Long id, Pageable pageable);
@EntityGraph(attributePaths = {"constructionTeam","user"})
Page<ConstructionMember> findAll(Pageable pageable);
@EntityGraph(attributePaths = {"constructionTeam","user"})
List<ConstructionMember> findAll();
@EntityGraph(attributePaths = {"constructionTeam","user"})
ConstructionMember findOne(Long id);
}
-这是我的模态映射器。
public ConstructionMember fillConstructionMemberForm(ConstructionMember destination,ConstructionMember form) {
modelMapper.map(form, destination);
return destination;
}
请帮助我! 。 谢谢大家。