このツールは、Netbeans 7.2 で ctrl+n を押して [Persistance] -> [Generate entity classes from Database] を選択すると見つかります。それはうまくいきます。
IntelliJ はスキーマからエンティティを生成するために別のもの ([Persistance] タブの [Generate persistnet mapping -> by database schema] オプション) を使用するため、IntelliJ で使用したいと思います。生成されたクラスは、プリミティブ型しか含まれていないため、役に立ちません
例えば:
私のスキーマの一部:
create table users (
id int not null primary key,
login varchar(64) not null unique,
pass char(150) not null
);
create table groups (
login varchar(64) not null,
group_name varchar(64) not null,
foreign key (login) references users (login)
);
IntelliJ によって生成されたエンティティの一部:
@Entity
public class Users
{
private Integer id;
@javax.persistence.Column(name = "id")
@Id
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id = id;
}
private String login;
@javax.persistence.Column(name = "login")
@Basic
public String getLogin()
{
return login;
}
public void setLogin(String login)
{
this.login = login;
}
private String pass;
@javax.persistence.Column(name = "pass")
@Basic
public String getPass()
{
return pass;
}
public void setPass(String pass)
{
this.pass = pass;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Users users = (Users) o;
if (id != null ? !id.equals(users.id) : users.id != null) return false;
if (login != null ? !login.equals(users.login) : users.login != null) return false;
if (pass != null ? !pass.equals(users.pass) : users.pass != null) return false;
return true;
}
@Override
public int hashCode()
{
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (login != null ? login.hashCode() : 0);
result = 31 * result + (pass != null ? pass.hashCode() : 0);
return result;
}
}
NetBeans によって生成されたエンティティの一部 (IntelliJ で使用したい正しい方法)
@Entity
@Table(name = "users", catalog = "soccerweb", schema = "public")
@NamedQueries({
@NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
@NamedQuery(name = "Users.findById", query = "SELECT u FROM Users u WHERE u.id = :id"),
@NamedQuery(name = "Users.findByLogin", query = "SELECT u FROM Users u WHERE u.login = :login"),
@NamedQuery(name = "Users.findByPass", query = "SELECT u FROM Users u WHERE u.pass = :pass")})
public class Users implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 64)
@Column(name = "login")
private String login;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 150)
@Column(name = "pass")
private String pass;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "userId", fetch = FetchType.LAZY)
private List<Achievements> achievementsList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "userId", fetch = FetchType.LAZY)
private List<BlueTeam> blueTeamList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "userId", fetch = FetchType.LAZY)
private List<RedTeam> redTeamList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "userId", fetch = FetchType.LAZY)
private List<TournamentPlayers> tournamentPlayersList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "userId", fetch = FetchType.LAZY)
private List<Stats> statsList;
@OneToMany(mappedBy = "userId", fetch = FetchType.LAZY)
private List<TournamentStats> tournamentStatsList;
@OneToMany(mappedBy = "userId", fetch = FetchType.LAZY)
private List<TournamentAchievements> tournamentAchievementsList;