2012-12-07 59 views
3

當您按下ctrl + n並選擇「Persistance - > Genarate entity classes from Database」時,可以在Netbeans 7.2中找到此工具。它效果很好。NetBeans使用什麼工具從數據庫中生成實體類?

我想在IntelliJ中使用它,因爲IntelliJ使用不同的東西(從Persistance選項卡中選擇「通過數據庫模式生成persistnet映射 - >生成persistnet映射」)來從模式生成實體。生成的類是沒有用的,因爲它們只包含基本類型

例如:

我的架構的一部分:

@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; 
    } 
} 

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產生實體的一部分部分由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; 
+0

不能你只需在Netbeans中創建它們,然後在Intellij中使用/修改它們? –

+0

我這樣做。但它不方便。 – mklimek

+0

然後它可能是一個很好的練習嘗試在代碼中查找功能,並查看您是否可以推斷它在一個可重用的功能。 由於Netbeans是基於ant的,你還可以在構建文件中找到一些有用的指針... –

回答

2

IDEA不支持它,我創建了一個新功能請求,please vote

您可能也有興趣在以下功能要求:

  • IDEA-64709 JPA:生成字段訪問
  • IDEA-67051通過創建Hibernate逆向工程逆向工程DAO對象的能力
+0

映射集合的IntelliJ中的默認值是集合,我可以將默認值更改爲List或Set嗎?或者是否必須手動更改數據庫架構映射框中的每個關係? –