2016-06-29 7 views
0

私はfundというテーブルを持っています。私は自分のクエリーを書くためにJPAを使いたいと思います。だから、私はIntelliJを使用して、自分のスキーマに基づいて永続マッピングを生成し、休止状態には基づいていません。JPAでエンティティをどのようにマップするのですか?

import javax.persistence.*; 
import java.sql.Timestamp; 

@Entity 
@Table(name = "fund", schema = "public", catalog = "db") 
public class FundEntity { 
    private long fundId; 
    private Timestamp createdAt; 
    private String description; 
    private Timestamp modTime; 
    private String modUser; 
    private String fundName; 
    private String fundType; 

    @Id 
    @Column(name = "fund_id") 
    public long getFundId() { 
     return fundId; 
    } 

    public void setFundId(long fundId) { 
     this.fundId = fundId; 
    } 

    @Basic 
    @Column(name = "created_at") 
    public Timestamp getCreatedAt() { 
     return createdAt; 
    } 

    public void setCreatedAt(Timestamp createdAt) { 
     this.createdAt = createdAt; 
    } 

    @Basic 
    @Column(name = "description") 
    public String getDescription() { 
     return description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 

    @Basic 
    @Column(name = "mod_time") 
    public Timestamp getModTime() { 
     return modTime; 
    } 

    public void setModTime(Timestamp modTime) { 
     this.modTime = modTime; 
    } 

    @Basic 
    @Column(name = "mod_user") 
    public String getModUser() { 
     return modUser; 
    } 

    public void setModUser(String modUser) { 
     this.modUser = modUser; 
    } 

    @Basic 
    @Column(name = "fund_name") 
    public String getFundName() { 
     return fundName; 
    } 

    public void setFundName(String fundName) { 
     this.fundName = fundName; 
    } 

    @Basic 
    @Column(name = "fund_type") 
    public String getFundType() { 
     return fundType; 
    } 

    public void setFundType(String fundType) { 
     this.fundType = fundType; 
    } 

    @Override 
    public boolean equals(Object o) { 
     if (this == o) return true; 
     if (o == null || getClass() != o.getClass()) return false; 

     FundEntity that = (FundEntity) o; 

     if (fundId != that.fundId) return false; 
     if (createdAt != null ? !createdAt.equals(that.createdAt) : that.createdAt != null) return false; 
     if (description != null ? !description.equals(that.description) : that.description != null) return false; 
     if (modTime != null ? !modTime.equals(that.modTime) : that.modTime != null) return false; 
     if (modUser != null ? !modUser.equals(that.modUser) : that.modUser != null) return false; 
     if (fundName != null ? !fundName.equals(that.fundName) : that.fundName != null) return false; 
     if (fundType != null ? !fundType.equals(that.fundType) : that.fundType != null) return false; 

     return true; 
    } 

    @Override 
    public int hashCode() { 
     int result = (int) (fundId^(fundId >>> 32)); 
     result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 
     result = 31 * result + (description != null ? description.hashCode() : 0); 
     result = 31 * result + (modTime != null ? modTime.hashCode() : 0); 
     result = 31 * result + (modUser != null ? modUser.hashCode() : 0); 
     result = 31 * result + (fundName != null ? fundName.hashCode() : 0); 
     result = 31 * result + (fundType != null ? fundType.hashCode() : 0); 
     return result; 
    } 
} 

そして、これが私のpersistence.xmlのです:

<?xml version="1.0" encoding="UTF-8"?> 

<persistence-unit name="postgres"> 
    <provider>org.hibernate.ejb.HibernatePersistence</provider> 
    <properties> 
     <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5443/db" /> 
     <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" /> 
     <property name="hibernate.connection.username" value="dba" /> 
     <property name="hibernate.connection.password" value="XXX" /> 
     <property name="hibernate.archive.autodetection" value="class" /> 
     <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect" /> 
     <property name="hibernate.show_sql" value="true"/> 
     <property name="hibernate.format_sql" value="true" /> 
     <property name="hibernate.flushMode" value="FLUSH_AUTO" /> 
     <property name="hibernate.hbm2ddl.auto" value="update" /> 
    </properties> 
</persistence-unit> 

その後、私は私のfundsを取得しようとしたが何もありませんで:

jpa-ql> select f from FundEntity f 
[2016-06-29 18:01:11] FundEntity is not mapped [select f from FundEntity f] 

私はここで何をしないのですか?私は自分のエンティティの発見が私のpersistence.xmlファイルで指定されてから自動的に行われると考えました。

答えて

関連する問題