4

如果有人为我的问题找到解决方案,我将不胜感激...

从我的 WebService 调用 Web 方法时,出现以下错误:

[com.sun.istack.SAXParseException2; 行号:1;列号:223;意外元素(uri:“”,本地:“运动”)。预期元素是 <{}mostFavored>、<{}teamA>、<{}teamB>、<{http://sdl.ws.lsep.lskings.com/}scoring>、<{http://sdl.ws .lsep.lskings.com/}sport>,<{}gameId>,<{http://sdl.ws.lsep.lskings.com/}gameScoring>]

我想知道为什么消息包含元素“sport”以及为什么它与 <{http://sdl.ws.lsep.lskings.com/}sport> 不匹配。我认为这与命名空间有关,但我无法解决这个问题,到目前为止我已经被困了两个晚上......

我正在使用 JBossWS 工具生成客户端 Web 服务,并且所有内容都部署在 JBoss 7.1.1 上(但我认为这无关紧要)。请至少给我任何线索:)

这是 GameScoring 类:

@Entity
@Table(name = "`GAMESCORING`")
@XmlRootElement
@XmlType(name = "GameScoring", propOrder = { "gameScoringId", "scoring", "finished", "startTime", "stopTime",
    "tiebreak" })
public class GameScoring implements Serializable {
@Id
@GeneratedValue
@Column(name = "game_scoring_id")
private long gameScoringId;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "scoring")
private List<GamePeriod> periods;

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "scoring_id")
private Scoring scoring;

private boolean finished;

private Date startTime;

private Date stopTime;

private GamePeriod tiebreak;

public GameScoring() {
    super();
}

以及在客户端生成的相同类:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "GameScoring", propOrder = {
"gameScoringId",
"scoring",
"finished",
"startTime",
"stopTime",
"tiebreak"
})

public class GameScoring {

protected long gameScoringId;
@XmlElement(namespace = "http://sdl.ws.lsep.lskings.com/")
protected Scoring scoring;
protected boolean finished;
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar startTime;
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar stopTime;
protected GamePeriod tiebreak;
+ getters/setters

我如何调用 Web 服务方法:

GameManagerService gm_service = new GameManagerService();
GameManagerPortType gm_port = gm_service.getGameManagerPort();
com.lskings.lsep.ws.sdl.Game game = gm_port.getMostFavored();

这里是网络服务 SEI:

@WebService(name = "GameManagerPortType")
@SOAPBinding(style = Style.RPC, use = Use.LITERAL)
public interface GameManagerEndpoint {

@WebMethod
@WebResult(name = "success")
public boolean addGame(
        @WebParam(name = "sportId") String sportId,
        @WebParam(name = "leagueId") String leagueId,
        @WebParam(name = "scoringId") String scoringId,
        @WebParam(name = "participantHomeId") long participantHomeId,
        @WebParam(name = "participantAwayId") long participantAwayId);

@WebMethod
@WebResult(name = "success")
public boolean deleteGame(@WebParam(name = "gameId") long gameId);

@WebMethod
@WebResult(name = "exists")
public boolean exists(@WebParam(name = "gameId") long gameId);

@WebMethod
@WebResult(name = "game")
public Game getGame(@WebParam(name = "gameId") long gameId);

@WebMethod
@WebResult(name = "gameList")
public List<Game> getGamesForLeague(@WebParam(name = "leagueId") long leagueId);

@WebMethod
@WebResult(name = "gameList")
public List<Game> search(@WebParam(name = "query") String query);

@WebMethod
@WebResult(name = "gameList")
public List<Game> getGamesForSport(@WebParam(name = "sportId") long sportId);

@WebMethod
@WebResult(name = "game")
public Game getMostFavored();

@WebMethod
@WebResult(name = "success")
public boolean setMostFavored(@WebParam(name = "gameId") long gameId);

@WebMethod
@WebResult(name = "gamePeriods")
public List<GamePeriod> getPeriods(@WebParam(name = "gameId") long gameId);

@WebMethod
@WebResult(name = "gamePeriodsWithTiebreaks")
public List<GamePeriod> getPeriodsWithTiebreaks(@WebParam(name = "gameId") long gameId);

@WebMethod
@WebResult(name = "gameScore")
public int[] getScore(@WebParam(name = "gameId") long gameId);

@WebMethod
@WebResult(name = "periodActions")
public List<GameAction> getPeriodActions(@WebParam(name = "periodId") long periodId);

@WebMethod
@WebResult(name = "allActions")
public List<GameAction> getAllActions(@WebParam(name = "gameId") long gameId);

@WebMethod
@WebResult(name = "gameTimer")
public String getGameTimer(@WebParam(name = "gameId") long gameId);

}

完整的堆栈跟踪:

http://pastebin.com/9pfCNFcw

Game.java - 服务器端

 @Entity
 @Table(name = "`GAME`")
 @XmlRootElement
 @XmlType(name = "Game", propOrder = { "gameId", "sport", "mostFavored" })
 public class Game implements Serializable {

private static final long serialVersionUID = -1564911377701558631L;

@Id
@GeneratedValue
@Column(name = "game_id")
private long gameId;

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "sport_id")
private Sport sport;

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "scoring_id")
private Scoring scoring;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "game_scoring_id")
private GameScoring gameScoring;

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "teamA_id")
private Participant teamA;

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "teamB_id")
private Participant teamB;

@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "league_id")
private League league;

@Column(name = "most_favored")
private boolean mostFavored;

public Game() {
    super();
}

public Game(Sport sport, Scoring scoring, Participant teamA, Participant teamB) {
    this(sport, scoring, teamA, teamB, null);
}

public Game(Sport sport, Scoring scoring, Participant teamA, Participant teamB, League league) {
    super();
    this.sport = sport;
    this.scoring = scoring;
    this.teamA = teamA;
    this.teamB = teamB;
    this.league = league;
    this.mostFavored = false;

    LinkedList<GamePeriod> periods = new LinkedList<GamePeriod>();

    this.gameScoring = new GameScoring();

    Period p = scoring.getPeriods().get(0);
    GamePeriod gp = new GamePeriod(p, gameScoring);
    periods.add(gp);
    gp.generateParents(true);

    gameScoring.setPeriods(periods);
    gameScoring.setScoring(scoring);
}

public Sport getSport() {
    return sport;
}

@XmlTransient
public Scoring getScoring() {
    return scoring;
}

@XmlTransient
public Participant getTeamA() {
    return teamA;
}

@XmlTransient
public Participant getTeamB() {
    return teamB;
}

@XmlTransient
public GameScoring getGameScoring() {
    return gameScoring;
}

public void setSport(Sport sport) {
    this.sport = sport;
}

public void setScoring(Scoring scoring) {
    this.scoring = scoring;
}

public void setGameScoring(GameScoring gameScoring) {
    this.gameScoring = gameScoring;
}

public void setTeamA(Participant teamA) {
    this.teamA = teamA;
}

public void setTeamB(Participant teamB) {
    this.teamB = teamB;
}

public long getGameId() {
    return gameId;
}

public void setGameId(long gameId) {
    this.gameId = gameId;
}

@XmlTransient
public League getLeague() {
    return league;
}

public void setLeague(League league) {
    this.league = league;
}

public boolean isMostFavored() {
    return mostFavored;
}

public void setMostFavored(boolean mostFavored) {
    this.mostFavored = mostFavored;
}

}

Game.java - 客户端:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Game", propOrder = {
"gameId",
"sport",
"mostFavored"
})
public class Game {

protected long gameId;
 //    @XmlElement(namespace = "http://sdl.ws.lsep.lskings.com/")
protected Sport sport;
protected boolean mostFavored;

/**
 * Gets the value of the gameId property.
 * 
 */
public long getGameId() {
    return gameId;
}

/**
 * Sets the value of the gameId property.
 * 
 */
public void setGameId(long value) {
    this.gameId = value;
}

/**
 * Gets the value of the sport property.
 * 
 * @return
 *     possible object is
 *     {@link Sport }
 *     
 */
public Sport getSport() {
    return sport;
}

/**
 * Sets the value of the sport property.
 * 
 * @param value
 *     allowed object is
 *     {@link Sport }
 *     
 */
public void setSport(Sport value) {
    this.sport = value;
}

/**
 * Gets the value of the mostFavored property.
 * 
 */
public boolean isMostFavored() {
    return mostFavored;
}

/**
 * Sets the value of the mostFavored property.
 * 
 */
public void setMostFavored(boolean value) {
    this.mostFavored = value;
}

}
4

1 回答 1

0

几天前我发现它与@ManyToOne 和@ManyToMany JPA 注释有关。但是,我不确定为什么在使用这些注释时会失败,@XmlTransient 注释解决了它。之后,我只需要编写一些额外的代码来通过 id 获取相关对象。

于 2012-07-11T16:08:44.237 回答