带有hibernate的com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

时间:2015-08-14 13:51:28

标签: java mysql hibernate maven jdbc

我无法看到问题出在哪里,我认为豆子里有某个地方,但我不知道在哪里。这是我的课程:

/* Desired result */

id A  B  C  dup_id
1  1  1  1  1
2  1  1  1  1
3  1  1  1  1
4  2  2  2  4
5  2  2  2  4
6  2  2  2  4
7  2  2  2  4
8  3  3  3  8
9  3  3  3  8
10 4  4  4  10

}

@Entity
@Table(name = "players")
public class Player implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer playerId;
@Column(name="player_name")
private String playerName;
@Column(name="player_country")
private String playerCountry;
@Column(name="player_championship_id")
private Integer championshipId;
@Column(name="player_team_id")
private Integer playerTeamId;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="championship_id",insertable=false,updatable=false)
private Championship championship;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="team_id",insertable=false,updatable=false)
private Team team;

public Integer getPlayerId() {
    return playerId;
}

public void setPlayerId(Integer playerId) {
    this.playerId = playerId;
}

public String getPlayerName() {
    return playerName;
}

public void setPlayerName(String playerName) {
    this.playerName = playerName;
}

public String getPlayerCountry() {
    return playerCountry;
}

public void setPlayerCountry(String playerCountry) {
    this.playerCountry = playerCountry;
}

public Championship getChampionship() {
    return championship;
}

public void setChampionship(Championship championship) {
    this.championship = championship;
}

public Team getTeam() {
    return team;
}

public void setTeam(Team team) {
    this.team = team;
}

}

@Entity
@Table(name = "teams")
public class Team {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="team_id")
private Integer teamId;
@Column(name="team_name")
private String teamName;
@Column(name="team_country")
private String teamCountry;
@Column(name="team_points")
private Double teamPoints;
@Column(name="team_championship_id")
private Integer championshipId;


@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="championship_id",insertable=false,updatable=false)
private Championship championship;
@OneToMany(mappedBy="team",fetch=FetchType.LAZY, cascade=CascadeType.REMOVE)
private List<Player> players;


public String getTeamName() {
    return teamName;
}
public void setTeamName(String teamName) {
    this.teamName = teamName;
}
public String getTeamCountry() {
    return teamCountry;
}
public void setTeamCountry(String teamCountry) {
    this.teamCountry = teamCountry;
}
public Double getTeamPoints() {
    return teamPoints;
}
public void setTeamPoints(Double teamPoints) {
    this.teamPoints = teamPoints;
}
public Integer getTeamId() {
    return teamId;
}
public void setTeamId(Integer teamId) {
    this.teamId = teamId;
}
public Championship getChampionship() {
    return championship;
}
public void setChampionship(Championship championship) {
    this.championship = championship;
}
public List<Player> getPlayers() {
    return players;
}
public void setPlayers(List<Player> players) {
    this.players = players;
}

以下是从我的数据库中检索数据的方法:

@Entity
@Table(name="championships")
@Component
public class Championship implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer championshipId;
@Column(name="championship_current_round")
private Integer currentRound;
@Column(name="championship_no_rounds")
private Integer noRounds;
@Column(name="championship_name")
private String championshipName;

@OneToMany(mappedBy="championship",fetch=FetchType.LAZY, cascade=CascadeType.REMOVE)
private List<Player>players;
@OneToMany(mappedBy="championship",fetch=FetchType.LAZY, cascade=CascadeType.REMOVE)
private List<Team>teams;

public Integer getChampionshipId() {
    return championshipId;
}
public void setChampionshipId(Integer championshipId) {
    this.championshipId = championshipId;
}
public Integer getCurrentRound() {
    return currentRound;
}
public void setCurrentRound(Integer currentRound) {
    this.currentRound = currentRound;
}
public Integer getNoRounds() {
    return noRounds;
}
public void setNoRounds(Integer noRounds) {
    this.noRounds = noRounds;
}
public String getChampionshipName() {
    return championshipName;
}
public void setChampionshipName(String championshipName) {
    this.championshipName = championshipName;
}



}

这是堆栈跟踪:

public T findById(Integer id){
    return (T) sessionFactory.getCurrentSession().get(managedClass.getClass(),(Serializable) id);
}
public List<T> findAll(){
    List<T>result= (List<T>)sessionFactory.getCurrentSession().createCriteria(managedClass.getClass()).list();
    return result;

}

问题在于:

SEVERE: Servlet.service() for servlet [spring] in context with path      [/HibernateTutorial2] threw exception [Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query] with root cause
 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'this_.championship_id' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2002)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at dao.GenericDao.findAll(GenericDao.java:36)
at service.TeamService.getAll(TeamService.java:18)
at service.TeamService$$FastClassBySpringCGLIB$$3a8e7bf.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
at service.TeamService$$EnhancerBySpringCGLIB$$6d41f206.getAll(<generated>)
at controller.IndexController.championships(IndexController.java:23)
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.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

0 个答案:

没有答案