JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Object Relational Mapping » Hibernate  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
作者 Hibernate annotation many to one多對一的不明錯誤
bluestone





發文: 19
積分: 0
於 2013-07-08 15:17 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位大哥,求救阿~
我有兩個表,其中一個是含復合主鍵,在查詢時候會一直出現下面的錯誤訊息...
我想應該是annotation錯誤,可是自己就是怎麼都看不出來哪邊錯?
不好意思請路過大俠解救....感謝感謝
錯誤訊息
1
Column HA0501 not in table KZ01 in TESTDB.

KZ01表(ManytoOne)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * Kz01 entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "KZ01", schema = "TESTDB", catalog = "TEST")
public class Kz01 implements java.io.Serializable {
 
  // Fields
 
  private Kz01Id id;
  private String kmemo;
  
 
  /** default constructor */
  public Kz01() {
  }
 
  /** full constructor */
  public Kz01(Kz01Id id, String kmemo) {
    this.id = id;
    this.kmemo = kmemo;
  }
  @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH},fetch = FetchType.LAZY)
    @JoinColumn(name = "id.kzpem")
  private Ha0501 ha0501;
  public Ha0501 getHa0501() {
    return ha0501;
  }
 
  public void setHa0501(Ha0501 ha0501) {
    this.ha0501 = ha0501;
  }
 
  // Property accessors
  @EmbeddedId
  @AttributeOverrides({
      @AttributeOverride(name = "kzpem", column = @Column(name = "KZPEM", nullable = false, precision = 7, scale = 0)),
      @AttributeOverride(name = "kzyer", column = @Column(name = "KZYER", nullable = false, precision = 4, scale = 0)),
      @AttributeOverride(name = "kztyp", column = @Column(name = "KZTYP", nullable = false, length = 2)),
      @AttributeOverride(name = "kzrno", column = @Column(name = "KZRNO", nullable = false, length = 14)) })
  public Kz01Id getId() {
    return this.id;
  }
 
  public void setId(Kz01Id id) {
    this.id = id;
  }
 
  @Column(name = "KMEMO", nullable = false, length = 42)
  public String getKmemo() {
    return this.kmemo;
  }
 
  public void setKmemo(String kmemo) {
    this.kmemo = kmemo;
  }
}

Kz01Id是myeclipse生成的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
 * Kz01Id entity. @author MyEclipse Persistence Tools
 */
@Embeddable
public class Kz01Id implements java.io.Serializable {
 
  // Fields
 
  private Integer kzpem;
  private Short kzyer;
  private String kztyp;
  private String kzrno;
 
  // Constructors
 
  /** default constructor */
  public Kz01Id() {
  }
 
  /** full constructor */
  public Kz01Id(Integer kzpem, Short kzyer, String kztyp, String kzrno) {
    this.kzpem = kzpem;
    this.kzyer = kzyer;
    this.kztyp = kztyp;
    this.kzrno = kzrno;
  }
 
  // Property accessors
 
  @Column(name = "KZPEM", nullable = false, precision = 7, scale = 0)
  public Integer getKzpem() {
    return this.kzpem;
  }
 
  public void setKzpem(Integer kzpem) {
    this.kzpem = kzpem;
  }
 
  @Column(name = "KZYER", nullable = false, precision = 4, scale = 0)
  public Short getKzyer() {
    return this.kzyer;
  }
 
  public void setKzyer(Short kzyer) {
    this.kzyer = kzyer;
  }
 
  @Column(name = "KZTYP", nullable = false, length = 2)
  public String getKztyp() {
    return this.kztyp;
  }
 
  public void setKztyp(String kztyp) {
    this.kztyp = kztyp;
  }
 
  @Column(name = "KZRNO", nullable = false, length = 14)
  public String getKzrno() {
    return this.kzrno;
  }
 
  public void setKzrno(String kzrno) {
    this.kzrno = kzrno;
  }
 
  public boolean equals(Object other) {
    if ((this == other))
      return true;
    if ((other == null))
      return false;
    if (!(other instanceof Kz01Id))
      return false;
    Kz01Id castOther = (Kz01Id) other;
 
    return ((this.getKzpem() == castOther.getKzpem()) || (this.getKzpem() != null
        && castOther.getKzpem() != null && this.getKzpem().equals(
        castOther.getKzpem())))
        && ((this.getKzyer() == castOther.getKzyer()) || (this
            .getKzyer() != null && castOther.getKzyer() != null && this
            .getKzyer().equals(castOther.getKzyer())))
        && ((this.getKztyp() == castOther.getKztyp()) || (this
            .getKztyp() != null && castOther.getKztyp() != null && this
            .getKztyp().equals(castOther.getKztyp())))
        && ((this.getKzrno() == castOther.getKzrno()) || (this
            .getKzrno() != null && castOther.getKzrno() != null && this
            .getKzrno().equals(castOther.getKzrno())));
  }
 
  public int hashCode() {
    int result = 17;
 
    result = 37 * result
        + (getKzpem() == null ? 0 : this.getKzpem().hashCode());
    result = 37 * result
        + (getKzyer() == null ? 0 : this.getKzyer().hashCode());
    result = 37 * result
        + (getKztyp() == null ? 0 : this.getKztyp().hashCode());
    result = 37 * result
        + (getKzrno() == null ? 0 : this.getKzrno().hashCode());
    return result;
  }
 
}

Ha0501表(OnetoMany)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
 * Ha0501 entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "HA0501", schema = "TESTDB", catalog = "TEST")
public class Ha0501 implements java.io.Serializable {
 
  // Fields
 
  private Integer hpemn;
  private String hname;
  private Set <Kz01> kz01;
 
  // Constructors  
 
  /** default constructor */
  public Ha0501() {
  }
 
  /** full constructor */
  public Ha0501(Integer hpemn, String hname) {
    this.hpemn = hpemn;
    this.hname = hname;
  }
 
  // Property accessors
  @Id
  @Column(name = "HPEMN", nullable = false, precision = 7, scale = 0)
  public Integer getHpemn() {
    return this.hpemn;
  }
 
  public void setHpemn(Integer hpemn) {
    this.hpemn = hpemn;
  }
 
  @Column(name = "HNAME", nullable = false, length = 10)
  public String getHname() {
    return this.hname;
  }
  @OneToMany(cascade={CascadeType.REMOVE},fetch=FetchType.EAGER,mappedBy = "id.kzpem")
  
  public Set<Kz01> getKz01() {
    return kz01;
  }
 
  public void setKz01(Set<Kz01> kz01) {
    this.kz01 = kz01;
  }
  
  
  public void setHname(String hname) {
    this.hname = hname;
  }
 
}

透過spring mvc執行
下面的取資料code,寫了好多就是跑不出SQL,郁悶阿~
1
2
3
4
5
6
7
8
9
10
11
@SuppressWarnings("unchecked")
  public List<Kz01> getAllKz01()
  {    
    
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Kz01.class);
////上面测试code都没用会跑出Column HA0501 not in table KZ01 in TESTDB的错误./////////
    return criteria.list();//原始用法
    
  }
 


我的目的想要產生以KZ01為主LEFT JOIN Ha0501
麻煩諸位幫忙看看...


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1743 Hibernate annotation many to one多對一的不明錯誤 bluestone 5946 2013-07-08 15:17
1755 Re:Hibernate annotation many to one多對一的不明錯誤 bluestone 568 2013-07-16 10:26
» JWorld@TW »  Object Relational Mapping » Hibernate

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8