0

生成表时,eclipse 说它不能识别 DogMall 类中的商店类型。而且我不能制作通用类实体,因为它们的类型无法在生成表时确定。确切的错误是“无法确定类 BaseballGame 上的关系属性事件的目标实体”。使用 eclipse 生成表时出现错误,而不是在问题视图中。我正在使用 Eclipse Juno SR1。

我不想发布代码,因为它非常大。简要说明我使用泛型是因为这个原因:如果我有一个 League 类和 BaseballLeague 的子类。League 有一个运动员列表,但我希望如果实例是 BaseballLeague,运动员必须是 BaseballPlayers 并避免客户端可以将 BaslketballPlayer 添加到 BaseballLeague 类,因为联盟有运动员列表。这在这个问题中得到了回答。这是受影响的代码:

package pqlrd.bll.sport;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import pqlrd.bll.pim.Person;
@Entity
/**
 * Athlete
 * @author jhonnytunes
 *
 */
public abstract class Athlete extends Person {


/**
 * 
 */
private static final long serialVersionUID = 3099827166939719897L;

@OneToOne(cascade=CascadeType.ALL, orphanRemoval=true)
private PhysicalCondition physicalCondition;

@OneToMany(cascade=CascadeType.ALL, orphanRemoval=true)
private List<PaymentCard> cards;

private List<ScoutingReport> report;

public Athlete() {
    // TODO Auto-generated constructor stub
}

public PhysicalCondition getPhysicalCondition() {
    return physicalCondition;
}

public void setPhysicalCondition(PhysicalCondition physicalCondition) {
    this.physicalCondition = physicalCondition;
}

public List<PaymentCard> getCards() {
    return cards;
}

public void setCards(List<PaymentCard> cards) {
    this.cards = cards;
}

public List<ScoutingReport> getReport() {
    return report;
}

public void setReport(List<ScoutingReport> report) {
    this.report = report;
}

public Athlete(PhysicalCondition physicalCondition,
        List<PaymentCard> cards, List<ScoutingReport> report) {
    super();
    this.physicalCondition = physicalCondition;
    this.cards = cards;
    this.report = report;
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((cards == null) ? 0 : cards.hashCode());
    result = prime
            * result
            + ((physicalCondition == null) ? 0 : physicalCondition
                    .hashCode());
    result = prime * result + ((report == null) ? 0 : report.hashCode());
    return result;
}


@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (!super.equals(obj))
        return false;
    if (getClass() != obj.getClass())
        return false;
    Athlete other = (Athlete) obj;
    if (cards == null) {
        if (other.cards != null)
            return false;
    } else if (!cards.equals(other.cards))
        return false;
    if (physicalCondition == null) {
        if (other.physicalCondition != null)
            return false;
    } else if (!physicalCondition.equals(other.physicalCondition))
        return false;
    if (report == null) {
        if (other.report != null)
            return false;
    } else if (!report.equals(other.report))
        return false;
    return true;
}


}

//////////////////////////////////////////////////////////////

 package pqlrd.bll.sport;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
/**
 * @author jhonnytunes
 *
 */
public abstract class BaseballEvent extends SportEvent<BaseballPlayer> {

/**
 * 
 */
private static final long serialVersionUID = 8163277354208426840L;

@Column(nullable = false)
private boolean onTop;

public void setOnTop(boolean onTop) {
    this.onTop = onTop;
}

public boolean isOnTop() {
    return onTop;
}

}
////////////////////////////////////////////////////
   package pqlrd.bll.sport;

import java.io.Serializable;
import java.util.LinkedList;
import javax.persistence.Entity;

@Entity
/**
 *  @author jhonnytunes
 *
 */
public class BaseballGame
        extends
    Game<BaseballPark, BaseballPlayer, BaseballEvent, BaseballCategory,             BaseballTeam>
    implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 2260373487163641360L;

}

////////////////////////////////////
package pqlrd.bll.sport;

import java.util.LinkedList;
import javax.persistence.Entity;

@Entity
/**
 * @author jhonnytunes
*/
public class BaseballLeague extends
    League<BaseballPark, BaseballPlayer, BaseballCategory> {

/**
 * 
 */
private static final long serialVersionUID = -3600825760889806131L;


}

//////////////////////////////////////////////////

package pqlrd.bll.sport;


import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
@Entity
/**
 * Baseball Player
 * @author jhonnytunes
 *
 */
public class BaseballPlayer extends Athlete {


@Enumerated(EnumType.STRING)
private Handedness _throws;


@Enumerated(EnumType.STRING)
private Handedness bats;


public BaseballPlayer() {
    // TODO Auto-generated constructor stub
}


public Handedness get_throws() {
    return _throws;
}


public void set_throws(Handedness _throws) {
    this._throws = _throws;
}


public Handedness getBats() {
    return bats;
}


public void setBats(Handedness bats) {
    this.bats = bats;
}


public BaseballPlayer(Handedness _throws, Handedness bats) {
    super();
    this._throws = _throws;
    this.bats = bats;
}

}

//////////////////////////////////////

package pqlrd.bll.sport;

import javax.persistence.Entity;

@Entity
/**
 * 
 * @author jhonnytunes
 *
 */
public class BaseballTournament
    extends
    Tournament<BaseballPark, BaseballPlayer, BaseballCategory, BaseballTeam,    TournamentInvitationBaseball, BaseballEvent, BaseballGame, BaseballLeague> {

/**
 * 
 */
private static final long serialVersionUID = 5315560497107867141L;

}


/////////////////////////////////

package pqlrd.bll.sport;

import java.io.Serializable;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import pqlrd.bll.pim.Person;

@MappedSuperclass
/**
 * Game
 * @author jhonnytunes
 */
public abstract class Game<P extends Park, A extends Athlete, SE extends SportEvent<A>, SC  extends SportCategory, T extends Team<A, SC>>
    implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = -1554044669639703370L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PQLRD_SEQ")
private long id;

@Column(nullable = false)
@Temporal(TemporalType.DATE)
private Calendar date;

@Column(nullable = false)
private boolean played;

@JoinColumn(nullable = false)
private P park;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private Map<Integer, SE> events;

@JoinColumn(nullable = false)
private T homeTeam;
@JoinColumn(nullable = false)
private T visitorTeam;

private Person scorer;

private List<A> homeAthletes;
private List<A> visitorAthletes;
public Calendar getDate() {
    return date;
}
public void setDate(Calendar date) {
    this.date = date;
}
public boolean isPlayed() {
    return played;
}
public void setPlayed(boolean played) {
    this.played = played;
}
public P getPark() {
    return park;
}
public void setPark(P park) {
    this.park = park;
}
public Map<Integer, SE> getEvents() {
    return events;
}
public void setEvents(Map<Integer, SE> events) {
    this.events = events;
}
public T getHomeTeam() {
    return homeTeam;
}
public void setHomeTeam(T homeTeam) {
    this.homeTeam = homeTeam;
}
public T getVisitorTeam() {
    return visitorTeam;
}
public void setVisitorTeam(T visitorTeam) {
    this.visitorTeam = visitorTeam;
}
public List<A> getHomeAthletes() {
    return homeAthletes;
}
public void setHomeAthletes(List<A> homeAthletes) {
    this.homeAthletes = homeAthletes;
}
public List<A> getVisitorAthletes() {
    return visitorAthletes;
}
public void setVisitorAthletes(List<A> visitorAthletes) {
    this.visitorAthletes = visitorAthletes;
}
public long getId() {
    return id;
}



public Person getScorer() {
    return scorer;
}
public void setScorer(Person scorer) {
    this.scorer = scorer;
}
public Game() {
    // TODO Auto-generated constructor stub
}
public Game(Calendar date, boolean played, P park, Map<Integer, SE> events,
        T homeTeam, T visitorTeam, List<A> homeAthletes,
        List<A> visitorAthletes) {
    super();
    this.date = date;
    this.played = played;
    this.park = park;
    this.events = events;
    this.homeTeam = homeTeam;
    this.visitorTeam = visitorTeam;
    this.homeAthletes = homeAthletes;
    this.visitorAthletes = visitorAthletes;
}
@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((date == null) ? 0 : date.hashCode());
    result = prime * result + ((events == null) ? 0 : events.hashCode());
    result = prime * result
            + ((homeAthletes == null) ? 0 : homeAthletes.hashCode());
    result = prime * result
            + ((homeTeam == null) ? 0 : homeTeam.hashCode());
    result = prime * result + (int) (id ^ (id >>> 32));
    result = prime * result + ((park == null) ? 0 : park.hashCode());
    result = prime * result + (played ? 1231 : 1237);
    result = prime * result
            + ((visitorAthletes == null) ? 0 :  visitorAthletes.hashCode());
    result = prime * result
            + ((visitorTeam == null) ? 0 : visitorTeam.hashCode());
    return result;
}
@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    Game other = (Game) obj;
    if (date == null) {
        if (other.date != null)
            return false;
    } else if (!date.equals(other.date))
        return false;
    if (events == null) {
        if (other.events != null)
            return false;
    } else if (!events.equals(other.events))
        return false;
    if (homeAthletes == null) {
        if (other.homeAthletes != null)
            return false;
    } else if (!homeAthletes.equals(other.homeAthletes))
        return false;
    if (homeTeam == null) {
        if (other.homeTeam != null)
            return false;
    } else if (!homeTeam.equals(other.homeTeam))
        return false;
    if (id != other.id)
        return false;
    if (park == null) {
        if (other.park != null)
            return false;
    } else if (!park.equals(other.park))
        return false;
    if (played != other.played)
        return false;
    if (visitorAthletes == null) {
        if (other.visitorAthletes != null)
            return false;
    } else if (!visitorAthletes.equals(other.visitorAthletes))
        return false;
    if (visitorTeam == null) {
        if (other.visitorTeam != null)
            return false;
    } else if (!visitorTeam.equals(other.visitorTeam))
        return false;
    return true;
}



}
////////////////////////////////
package pqlrd.bll.sport;

import java.io.Serializable;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.WordUtils;

import pqlrd.bll.cms.Attachment;
import pqlrd.bll.money.Payment;
import pqlrd.bll.pim.Address;
import pqlrd.bll.pim.ContactInformation;


@MappedSuperclass
/**
 * League class
 * @author jhonnytunes
 *
 */
public abstract class League<P extends Park, A extends Athlete, SC extends  SportCategory> implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = -6036071460102749097L;

@Id@GeneratedValue(strategy= GenerationType.SEQUENCE,generator="PQLRD_SEQ") 
private int id;

@Column(length=30, nullable=false)
private String name;

@Column(nullable=false)
@Temporal(TemporalType.DATE)
private Calendar dateOfOrigin;

@Column(columnDefinition="text")
private String history;

@ElementCollection
private List<String> requirements;

private List<AthletesCost> athletesCosts;

@Column(nullable=false)
private boolean visible;

private P park;

@OneToMany(cascade=CascadeType.ALL, orphanRemoval=true)
private List<LeagueStaff> leagueStaffs;

@OneToOne(cascade=CascadeType.ALL, orphanRemoval=true)
private List<ContactInformation>contactInformations;

@OneToOne(cascade=CascadeType.ALL, orphanRemoval=true)
private Address address;

@OneToMany(cascade=CascadeType.ALL, orphanRemoval=true)
private List<Team<A, SC>> teams;

@OneToMany(cascade=CascadeType.ALL, orphanRemoval=true)
private List<Attachment> attachments;

public String getName() {
    return WordUtils.capitalizeFully(name);
}

public void setName(String name) {
    this.name = name.toLowerCase();
}

public Calendar getDateOfOrigin() {
    return dateOfOrigin;
}

public void setDateOfOrigin(Calendar dateOfOrigin) {
    this.dateOfOrigin = dateOfOrigin;
}

public String getHistory() {
    return history;
}

public void setHistory(String history) {
    this.history = history;
}

public List<String> getRequirements() {
    return requirements;
}

public void setRequirements(List<String> requirements) {
    this.requirements = requirements;
}

public List<AthletesCost> getAthletesCosts() {
    return athletesCosts;
}

public void setAthletesCosts(List<AthletesCost> athletesCosts) {
    this.athletesCosts = athletesCosts;
}

public boolean isVisible() {
    return visible;
}

public void setVisible(boolean visible) {
    this.visible = visible;
}

public P getPark() {
    return park;
}

public void setPark(P park) {
    this.park = park;
}

public List<LeagueStaff> getLeagueStaffs() {
    return leagueStaffs;
}

public void setLeagueStaffs(List<LeagueStaff> leagueStaffs) {
    this.leagueStaffs = leagueStaffs;
}

public List<ContactInformation> getContactInformations() {
    return contactInformations;
}

public void setContactInformations(List<ContactInformation> contactInformations) {
    this.contactInformations = contactInformations;
}

public Address getAddress() {
    return address;
}

public void setAddress(Address address) {
    this.address = address;
}

public List<Team<A, SC>> getTeams() {
    return teams;
}

public void setTeams(List<Team<A, SC>> teams) {
    this.teams = teams;
}

public List<Attachment> getAttachments() {
    return attachments;
}

public void setAttachments(List<Attachment> attachments) {
    this.attachments = attachments;
}

public int getId() {
    return id;
}


public League() {
    // TODO Auto-generated constructor stub
}

public League(String name, Calendar dateOfOrigin, String history,
        List<String> requirements, List<AthletesCost> athletesCosts,
        boolean visible, P park, List<LeagueStaff> leagueStaffs,
        List<ContactInformation> contactInformations, Address address,
        List<Team<A, SC>> teams, List<Attachment> attachments) {
    super();
    this.name = name;
    this.dateOfOrigin = dateOfOrigin;
    this.history = history;
    this.requirements = requirements;
    this.athletesCosts = athletesCosts;
    this.visible = visible;
    this.park = park;
    this.leagueStaffs = leagueStaffs;
    this.contactInformations = contactInformations;
    this.address = address;
    this.teams = teams;
    this.attachments = attachments;
}




}

/////////////////////////////

package pqlrd.bll.sport;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang.math.NumberUtils;

import pqlrd.bll.util.NumbersUtil;
@IdClass(SportEventPK.class)
@MappedSuperclass
/**
 * Event that occur in a time of a game
 * @author jhonnytunes
 *
 */

public abstract class SportEvent<T extends Athlete> implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 3814280347145588159L;

@Id private T athlete;
@Id private short period;
@Id private long random;
@Id private short quantity;



public T getAthlete() {
    return athlete;
}
public void setAthlete(T athlete) {
    this.athlete = athlete;
}
public short getPeriod() {
    return period;
}
public void setPeriod(short period) {
    this.period = period;
}
public long getRandom() {
    return random;
}

public SportEvent() {

    this.random = NumbersUtil.random.nextLong();
}
public short getQuantity() {
    return quantity;
}
public void setQuantity(short quantity) {
    this.quantity = quantity;
}



}

//////////////////////////////

package pqlrd.bll.sport;

import java.io.Serializable;

import javax.persistence.Embeddable;

public class SportEventPK implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = -1251889014150257402L;

private Athlete athlete;
private short period;
private long random;
private short quantity;



public short getQuantity() {
    return quantity;
}

public void setQuantity(short quantity) {
    this.quantity = quantity;
}

public SportEventPK() {
    // TODO Auto-generated constructor stub
}

protected Athlete getAthlete() {
    return athlete;
}

protected void setAthlete(Athlete athlete) {
    this.athlete = athlete;
}

protected short getPeriod() {
    return period;
}

protected void setPeriod(short period) {
    this.period = period;
}

protected long getRandom() {
    return random;
}

protected void setRandom(long random) {
    this.random = random;
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((athlete == null) ? 0 : athlete.hashCode());
    result = prime * result + period;
    result = prime * result + (int) (random ^ (random >>> 32));
    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    SportEventPK other = (SportEventPK) obj;
    if (athlete == null) {
        if (other.athlete != null)
            return false;
    } else if (!athlete.equals(other.athlete))
        return false;
    if (period != other.period)
        return false;
    if (random != other.random)
        return false;
    return true;
}

}
/////////////////////////

package pqlrd.bll.sport;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
@MappedSuperclass

/**
 * @author jhonnytunes
 *
 */
public abstract class Team<A extends Athlete, SC extends SportCategory > implements     Serializable {

/**
 * 
 */
private static final long serialVersionUID = 5556278910044704061L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PQLRD_SEQ")
private int id;

@OneToMany(cascade=CascadeType.ALL, orphanRemoval=true)
private List<PracticeTime> times;

@JoinColumn(nullable=false)
private SC category;

private List<A> athletes;

public List<PracticeTime> getTimes() {
    return times;
}

public void setTimes(List<PracticeTime> times) {
    this.times = times;
}

public SC getCategory() {
    return category;
}

public void setCategory(SC category) {
    this.category = category;
}

public List<A> getAthletes() {
    return athletes;
}

public void setAthletes(List<A> athletes) {
    this.athletes = athletes;
}

public int getId() {
    return id;
}

public Team() {
    // TODO Auto-generated constructor stub
}

public Team(List<PracticeTime> times, SC category, List<A> athletes) {
    super();
    this.times = times;
    this.category = category;
    this.athletes = athletes;
}


}
4

2 回答 2

1

解决了。从作为映射超类的集合的属性中删除了 @OneToMany 注释。

于 2012-12-09T16:44:58.703 回答
0

将 OneToMany 字段下移到子类。

于 2012-12-06T14:50:54.597 回答