gpt4 book ai didi

java - 不要在Web应用程序spring mvc + jpa + postgreSQL中获取所有用户对象

转载 作者:行者123 更新时间:2023-12-03 23:15:48 24 4
gpt4 key购买 nike

我使用 spring MVC、JPA、postgreSQL 开发 Web 应用程序

这是一些代码:

文件:user.java

@Entity
@Table(name = "USER")
public class User implements Serializable{
private Long id;
private String name;
private DateTime birthDate;
private String address;
private String email;
private String phone;
private String username;
private String password;
private boolean isActive;
private String lastModifiedPerson;
private DateTime createdDate;
private DateTime lastModifiedDate;
private int version;

private Set<Role> roles = new HashSet<Role>();
private Set<Entry> entrys = new HashSet<Entry>();
private Set<EntryComment> comments = new HashSet<EntryComment>();



@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="ID")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}

@Column(name="NAME")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}


@Column(name="BIRTHDATE")
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@DateTimeFormat(iso=ISO.DATE)
public DateTime getBirthDate() {
return birthDate;
}
public void setBirthDate(DateTime birthDate) {
this.birthDate = birthDate;
}

@Column(name="ADDRESS")
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}

@Column(name="EMAIL")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}

@Column(name="PHONE")
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}

@Column(name="USERNAME")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}

@Column(name="PASSWORD")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

@Column(name="ISACTIVE")
public boolean isActive() {
return isActive;
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
@Column(name="LAST_MODIFIED_BY")
public String getLastModifiedPerson() {
return lastModifiedPerson;
}
public void setLastModifiedPerson(String lastModifiedPerson) {
this.lastModifiedPerson = lastModifiedPerson;
}

@Column(name="CREATE_DATE")
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@DateTimeFormat(iso=ISO.DATE)
public DateTime getCreatedDate() {
return createdDate;
}
public void setCreatedDate(DateTime createdDate) {
this.createdDate = createdDate;
}

@Column(name="LAST_MODIFIED_DATE")
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@DateTimeFormat(iso=ISO.DATE)
public DateTime getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(DateTime lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}

@Transient
public String getBirthDateString(){
String birthDateString="";
if(birthDate != null)
birthDateString = org.joda.time.format.DateTimeFormat
.forPattern("yyyy-MM-dd").print(birthDate);
return birthDateString;
}

@Transient
public String getLastModifiedDateString(){
String birthDateString="";
if(lastModifiedDate != null)
birthDateString = org.joda.time.format.DateTimeFormat
.forPattern("yyyy-MM-dd").print(lastModifiedDate);
return birthDateString;
}

@Transient
public String getCreateDateString(){
String birthDateString="";
if(createdDate != null)
birthDateString = org.joda.time.format.DateTimeFormat
.forPattern("yyyy-MM-dd").print(createdDate);
return birthDateString;
}

@ManyToMany
@JoinTable(name = "USER_ROLE",
joinColumns = @JoinColumn(name="USER_ID"),
inverseJoinColumns=@JoinColumn(name="ROLE_ID"))
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}

@OneToMany(mappedBy="user", cascade= CascadeType.ALL, orphanRemoval=true)
public Set<Entry> getEntrys() {
return entrys;
}
public void setEntrys(Set<Entry> entrys) {
this.entrys = entrys;
}

@OneToMany(mappedBy="user", cascade = CascadeType.ALL, orphanRemoval = true)
public Set<EntryComment> getComments() {
return comments;
}
public void setComments(Set<EntryComment> comments) {
this.comments = comments;
}

@Version
@Column(name="VERSION")
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}

@Override
public String toString(){
return "User - Id:" + id +", Name: "+ name +", Username: " + username +", CreatedDate: " + createdDate;
}
}

文件:UserRepository.java
package com.software.booksocial.repository;

import org.springframework.data.repository.CrudRepository;
import com.software.booksocial.domain.User;

public interface UserRepository extends CrudRepository<User, Long> {

}

文件:UserService.java
package com.software.booksocial.service;
import java.util.List;
import com.software.booksocial.domain.User;

public interface UserService {
List<User> findAll();
User findById(Long id);
User save(User user);
}

文件:UserServiceIml.java
package com.software.booksocial.service.jpa;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.software.booksocial.domain.User;
import com.software.booksocial.repository.UserRepository;
import com.software.booksocial.service.UserService;
import com.google.common.collect.Lists;

@Repository
@Transactional
@Service("userService")
public class UserServiceIml implements UserService {
@Autowired
private UserRepository userRepository;

@Override
@Transactional(readOnly = true)
public List<User> findAll(){
return Lists.newArrayList(userRepository.findAll());
}

@Override
@Transactional(readOnly=true)
public User findById(Long id){
return userRepository.findOne(id);
}

@Override
public User save(User user){
return userRepository.save(user);
}

//@Autowired
//public void setUserRepository(UserRepository userRepository){
// this.userRepository = userRepository;
//}
}

文件:UserController.java
package com.software.booksocial.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.software.booksocial.domain.User;
import com.software.booksocial.service.UserService;

@RequestMapping("/users")
@Controller
public class UserController {

final Logger logger = LoggerFactory.getLogger(UserController.class);

@Autowired
private UserService userService;

@RequestMapping(method = RequestMethod.GET)
public String list(Model uiModel){
logger.info("Listing Users");

List<User> users = userService.findAll();

uiModel.addAttribute("users", users);

logger.info("No. of users: " + users.size());

return "users/list";
}

}

和图片链接中的数据库结构:

https://dl.dropboxusercontent.com/u/39630113/DBBookSocial.png

https://dl.dropboxusercontent.com/u/39630113/Picture/DBUpdate.png

主要错误:

Hibernate: select user0_.ID as ID1_8_, user0_.ISACTIVE as ISACTIVE2_8_, user0_.ADDRESS as ADDRESS3_8_, user0_.BIRTHDATE as BIRTHDAT4_8_, user0_.CREATE_DATE as CREATE_D5_8_, user0_.EMAIL as EMAIL6_8_, user0_.LAST_MODIFIED_DATE as LAST_MOD7_8_, user0_.LAST_MODIFIED_BY as LAST_MOD8_8_, user0_.NAME as NAME9_8_, user0_.PASSWORD as PASSWOR10_8_, user0_.PHONE as PHONE11_8_, user0_.USERNAME as USERNAM12_8_, user0_.VERSION as VERSION13_8_ from USER user0_ WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42703 ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: column user0_.id does not exist Position: 8 Jan 27, 2015 4:37:45 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [appServlet] in context with path [/readersocial] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist Position: 8



和错误文本:

Hibernate: select user0_.ID as ID1_8_, user0_.ISACTIVE as ISACTIVE2_8_, user0_.ADDRESS as ADDRESS3_8_, user0_.BIRTHDATE as BIRTHDAT4_8_, user0_.CREATE_DATE as CREATE_D5_8_, user0_.EMAIL as EMAIL6_8_, user0_.LAST_MODIFIED_DATE as LAST_MOD7_8_, user0_.LAST_MODIFIED_BY as LAST_MOD8_8_, user0_.NAME as NAME9_8_, user0_.PASSWORD as PASSWOR10_8_, user0_.PHONE as PHONE11_8_, user0_.USERNAME as USERNAM12_8_, user0_.VERSION as VERSION13_8_ from USER user0_ WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42703 ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: column user0_.id does not exist Position: 8 Jan 27, 2015 4:37:45 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [appServlet] in context with path [/readersocial] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist Position: 8 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:304) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82) at org.hibernate.loader.Loader.getResultSet(Loader.java:2066) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839) at org.hibernate.loader.Loader.doQuery(Loader.java:910) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355) at org.hibernate.loader.Loader.doList(Loader.java:2554) at org.hibernate.loader.Loader.doList(Loader.java:2540) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370) at org.hibernate.loader.Loader.list(Loader.java:2365) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387) at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1264) at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103) at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573) at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449) at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:67) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:288) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:62) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:442) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:427) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:381) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.repository.core.support.RepositoryFactorySupport$DefaultMethodInvokingMethodInterceptor.invoke(RepositoryFactorySupport.java:512) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111) 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.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy36.findAll(Unknown Source) at com.software.booksocial.service.jpa.UserServiceIml.findAll(UserServiceIml.java:25) at com.software.booksocial.controller.UserController.list(UserController.java:30) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:78) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1033) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)

Jan 27, 2015 5:00:48 PM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/readersocial] has started Jan 27, 2015 5:00:48 PM org.apache.catalina.core.ApplicationContext log INFO: Destroying Spring FrameworkServlet 'appServlet' INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing WebApplicationContext for namespace 'appServlet-servlet': startup date [Tue Jan 27 16:37:28 ICT 2015]; parent: Root WebApplicationContext Jan 27, 2015 5:00:48 PM org.apache.catalina.core.ApplicationContext log INFO: Closing Spring root WebApplicationContext INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Tue Jan 27 16:37:17 ICT 2015]; root of context hierarchy Jan 27, 2015 5:00:48 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc SEVERE: The web application [/readersocial] registered the JDBC driver [org.postgresql.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. Jan 27, 2015 5:00:56 PM org.apache.catalina.core.ApplicationContext log INFO: No Spring WebApplicationInitializer types detected on classpath Jan 27, 2015 5:00:56 PM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring root WebApplicationContext INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Tue Jan 27 17:00:56 ICT 2015]; root of context hierarchy INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml] INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [datasource-tx-jpa.xml] INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring WARN : org.hibernate.ejb.HibernatePersistence - HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead. INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 13934 ms Jan 27, 2015 5:01:10 PM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring FrameworkServlet 'appServlet' INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Tue Jan 27 17:01:10 ICT 2015]; parent: Root WebApplicationContext INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml] INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/users],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.software.booksocial.controller.UserController.list(org.springframework.ui.Model) INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.software.booksocial.HomeController.home(java.util.Locale,org.springframework.ui.Model) INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: WebApplicationContext for namespace 'appServlet-servlet': startup date [Tue Jan 27 17:01:10 ICT 2015]; parent: Root WebApplicationContext INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: WebApplicationContext for namespace 'appServlet-servlet': startup date [Tue Jan 27 17:01:10 ICT 2015]; parent: Root WebApplicationContext INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0' INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 1486 ms Jan 27, 2015 5:01:12 PM org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/readersocial] is completed



我没有使用 spring 数据 jpa 从 UserController 的表 USER 中获取所有用户。谢谢你的帮助。

最佳答案

user是 Postgres 中的保留关键字(正如您在评论中所说),因此您最好的选择是将表重命名为其他名称(如 APP_USER )并将实体映射更改为 @Table(name = "APP_USER") .

如果您不能/不想更改表名,则无论在何处使用表名,都必须将表名括在双引号中,以 @Table(name = " \"USER\"") 开头。 ,但如果我没记错的话,当您查询与 User 相关的其他实体时,这会导致我上次尝试时出现一些错误。 (双引号未应用于 join 语句中,但现在可以修复)。

无论如何,退房this thread了解更多信息。

关于java - 不要在Web应用程序spring mvc + jpa + postgreSQL中获取所有用户对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28168267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com