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

» JWorld@TW » Java Application Framework  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 請問 hibernate annotations saveorupdate 設定方式
livecoff





發文: 14
積分: 0
於 2012-08-23 01:30 user profilesend a private message to usersend email to livecoffreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問各位大大 hibernate annotations 使用方式
我目前遇到的狀況是, 使用 saveorupdate 做insert 時可以正常執行
但是我要用 saveorupdate 做update 就出現KEY 值重複
以下是我的CODE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@MappedSuperclass
public class BaseModel implements Serializable {
  /**
   * 
   */
  private int sn;
  
  
  @GeneratedValue(strategy = GenerationType.AUTO)
  public int getSn() {
    return sn;
  }
 
  public void setSn(int sn) {
    this.sn = sn;
  }
  
}


Entity
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
@Entity()
@Table(name="car_car")
public class CarCar extends BaseModel {
  
  private String orgid;    //車輛所屬機關
  private String name;    //車輛型式
  private String carid;    //車牌號碼
  private Integer cc;      //排氣量
  private String oil;      //用油種類
  private String color;    //車體顏色
  private Integer psnger;    //限乘人數
  private String rent;    //購買租賃
  private String engid;    //引擎號碼
  private String pspoid;    //行照號碼
  private String rentco;    //租用公司
  private String rentedate;  //租賃到期日
  private Integer buymny;    //購買金額
  private String ofdate;    //出廠年月
  private String volume;    //總重量
  private String insuredate;  //車險到期日
  private String mnger;    //車輛管理人
  private String driver;    //預設駕駛
  private Integer mileage;  //目前里程數
  private String situation;  //車輛狀態
  private String memo;    //備註
  private String userid;    //更新資料人員
  private String renew;    //更新資料日期
  
  
  @Column(name="orgid", nullable=false, length=50)
  public String getOrgid() {
    return orgid;
  }
  
  @Column(name="name", nullable=false , length=50)
  public String getName() {
    return name;
  }
  
  
  @Column(name="carid",unique=true, nullable=false, length =10 )
  public String getCarid() {
    return carid;
  }
  
  @Column(name="cc", nullable=false, length=10)
  public Integer getCc() {
    return cc;
  }
  
  @Column(name="oil", nullable=false, length=50)
  public String getOil() {
    return oil;
  }
  
  @Column(name="color", nullable=false, length=50)
  public String getColor() {
    return color;
  }
  
  @Column(name="psnger", nullable=false)
  public Integer getPsnger() {
    return psnger;
  }
  
  @Column(name="rent", length=10)
  public String getRent() {
    return rent;
  }
  
  @Column(name="engid", length=50)
  public String getEngid() {
    return engid;
  }
  
  @Column(name="pspoid", length=50)
  public String getPspoid() {
    return pspoid;
  }
  
  @Column(name="rentco", length=50)
  public String getRentco() {
    return rentco;
  }
  
  @Column(name="rentedate", length=50)
  public String getRentedate() {
    return rentedate;
  }
  
  @Column(name="buymny")
  public Integer getBuymny() {
    return buymny;
  }
  
  @Column(name="ofdate", length=10)
  public String getOfdate() {
    return ofdate;
  }
  
  @Column(name="volume", length=10)
  public String getVolume() {
    return volume;
  }
  
  @Column(name="insuredate", length=10)
  public String getInsuredate() {
    return insuredate;
  }
  
  @Column(name="mnger", nullable=false, length=50)
  public String getMnger() {
    return mnger;
  }
  
  @Column(name="driver", length=50)
  public String getDriver() {
    return driver;
  }
  
  @Column(name="mileage")
  public Integer getMileage() {
    return mileage;
  }
  
  @Column(name="situation", nullable=false, length=10)
  public String getSituation() {
    return situation;
  }
  
  @Column(name="memo")
  public String getMemo() {
    return memo;
  }
  
  @Column(name="userid", length=10)
  public String getUserid() {
    return userid;
  }
  
  @Column(name="renew", length=16)
  public String getRenew() {
    return renew;
  }
 
  public void setOrgid(String orgid) {
    this.orgid = orgid;
  }
 
  public void setName(String name) {
    this.name = name;
  }
 
  public void setCarid(String carid) {
    this.carid = carid;
  }
 
  public void setCc(Integer cc) {
    this.cc = cc;
  }
 
  public void setOil(String oil) {
    
    this.oil = oil;
  }
 
  public void setColor(String color) {
    this.color = color;
  }
 
  public void setPsnger(Integer psnger) {
    this.psnger = psnger;
  }
 
  public void setRent(String rent) {
    this.rent = rent;
  }
 
  public void setEngid(String engid) {
    this.engid = engid;
  }
 
  public void setPspoid(String pspoid) {
    this.pspoid = pspoid;
  }
 
  public void setRentco(String rentco) {
    this.rentco = rentco;
  }
 
  public void setRentedate(String rentedate) {
    this.rentedate = rentedate;
  }
 
  public void setBuymny(Integer buymny) {
    this.buymny = buymny;
  }
 
  public void setOfdate(String ofdate) {
    this.ofdate = ofdate;
  }
 
  public void setVolume(String volume) {
    this.volume = volume;
  }
 
  public void setInsuredate(String insuredate) {
    this.insuredate = insuredate;
  }
 
  public void setMnger(String mnger) {
    this.mnger = mnger;
  }
 
  public void setDriver(String driver) {
    this.driver = driver;
  }
 
  public void setMileage(Integer mileage) {
    this.mileage = mileage;
  }
 
  public void setSituation(String situation) {
    this.situation = situation;
  }
 
  public void setMemo(String memo) {
    this.memo = memo;
  }
 
  public void setUserid(String userid) {
    this.userid = userid;
  }
 
  public void setRenew(String renew) {
    this.renew = renew;
  }
  
  
}




reply to postreply to post
學習~學習~不斷的學的是邁向成功的捷徑。
作者 Re:請問 hibernate annotations saveorupdate 設定方式 [Re:livecoff]
kentyeh





發文: 647
積分: 6
於 2012-08-23 09:36 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
乍看下應該沒什麼錯,除了沒有在 getSn()前冠上一個 @id

reply to postreply to post
作者 Re:請問 hibernate annotations saveorupdate 設定方式 [Re:kentyeh]
livecoff





發文: 14
積分: 0
於 2012-08-24 00:10 user profilesend a private message to usersend email to livecoffreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝 kentyeh 指點..... 終於可以用了,感激不盡....
Big Smile


reply to postreply to post
學習~學習~不斷的學的是邁向成功的捷徑。
» JWorld@TW »  Java Application Framework

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

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8