`
a137268431
  • 浏览: 157628 次
文章分类
社区版块
存档分类
最新评论

Hibernate4 更新部分更改的字段 hibernate update

 
阅读更多

Hibernate 中如果直接使用

<wbr></wbr>

Session.update(Object o);

<wbr>注意:很多人用Sesion.get()/load()查到某个对象后 用<span style="word-wrap:normal; word-break:normal">Session.update()</span>,发现自己想更新的字段更新了,但是其他的字段却变成了空,为什么呢? 原因是<span style="word-wrap:normal; word-break:normal">Sesion.get()/load()和</span><span style="word-wrap:normal; word-break:normal">Session.update()用了不同的session.</span></wbr>

会把这个表中的所有字段更新一遍。

<wbr></wbr>

比如:

<wbr></wbr>

[java]<wbr><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="view plain" style="text-decoration:none; color:rgb(62,115,160)">view plain</a><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="copy" style="text-decoration:none; color:rgb(62,115,160)">copy</a> <div></div> </wbr>
  1. public<wbr></wbr>class<wbr>TeacherTest<wbr>{<wbr><wbr></wbr></wbr></wbr></wbr>
  2. <wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(100,100,100); background-color:inherit">@Test</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr><wbr></wbr></wbr></span></wbr></wbr></wbr></wbr>
  3. <wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(0,102,153); background-color:inherit"><strong>public</strong></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(0,102,153); background-color:inherit"><strong>void</strong></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr>update(){<wbr><wbr></wbr></wbr></wbr></span></wbr></wbr></wbr></wbr>
  4. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Session<wbr>session<wbr>=<wbr><wbr>HibernateUitl.getSessionFactory().getCurrentSession();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  5. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>session.beginTransaction();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  6. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Teacher<wbr>t<wbr>=<wbr>(Teacher)<wbr>session.get(Teacher.<span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(0,102,153); background-color:inherit"><strong>class</strong></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">,<wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(192,0,0); background-color:inherit">3</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">);<wbr><wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  7. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>t.setName(<span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"yangtb2"</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">);<wbr><wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  8. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>session.update(t);<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  9. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  10. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>session.getTransaction().commit();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  11. <wbr><wbr><wbr><wbr>}<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  12. }<wbr><wbr></wbr></wbr>

<wbr></wbr>

Hibernate 执行的SQL语句:

<wbr></wbr>

<wbr></wbr>

[xhtml]<wbr><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="view plain" style="text-decoration:none; color:rgb(62,115,160)">view plain</a><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="copy" style="text-decoration:none; color:rgb(62,115,160)">copy</a> <div></div> </wbr>
  1. Hibernate:<wbr><wbr><wbr></wbr></wbr></wbr>
  2. <wbr><wbr><wbr><wbr>update<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  3. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Teacher<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  4. <wbr><wbr><wbr><wbr>set<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  5. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:red; background-color:inherit">age</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">=?,<wbr><wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  6. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:red; background-color:inherit">birthday</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">=?,<wbr><wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  7. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:red; background-color:inherit">name</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">=?,<wbr><wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  8. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:red; background-color:inherit">title</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">=?<wbr><wbr><wbr></wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  9. <wbr><wbr><wbr><wbr>where<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  10. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:red; background-color:inherit">id</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">=?<wbr><wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr></wbr>

我们只更改了Name属性,而Hibernate 的sql语句 把所有字段都更改了一次。

<wbr></wbr>

这样要是我们有字段是文本类型,这个类型存储的内容是几千,几万字,这样效率会很低。

那么怎么只更改我们更新的字段呢?

<wbr></wbr>

有三中方法:

<wbr>1.XML中设置property 标签 update = "false" ,如下:我们设置 age 这个属性在更改中不做更改</wbr>

<wbr></wbr>

[xhtml]<wbr><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="view plain" style="text-decoration:none; color:rgb(62,115,160)">view plain</a><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="copy" style="text-decoration:none; color:rgb(62,115,160)">copy</a> <div></div> </wbr>
  1. <</span>property<wbr></wbr>name="age"<wbr></wbr>update="false"></</span>property><wbr><wbr></wbr></wbr>
<wbr style="color:rgb(70,70,70); font-family:simsun; font-size:14.399999618530273px; line-height:21.600000381469727px; background-color:rgb(188,211,229)"><span style="color:rgb(70,70,70); font-family:simsun; font-size:14.399999618530273px; line-height:21.600000381469727px; background-color:rgb(188,211,229)"></span> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr>在Annotation中<wbr>在属性GET方法上加上@Column(updatable=false)</wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <div style="color:rgb(70,70,70); line-height:21.600000381469727px; font-family:Consolas,'Courier new',Courier,mono,serif; background-color:rgb(231,229,220); width:687.0499877929688px; overflow:auto; padding-top:1px; margin:18px 0px!important"> <div style="padding-left:45px"> <div style="padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(108,226,108)"> <strong>[java]</strong><wbr><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="view plain" style="text-decoration:none; color:rgb(62,115,160)">view plain</a><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="copy" style="text-decoration:none; color:rgb(62,115,160)">copy</a> <div></div> </wbr> </div> </div> <ol start="1" style="margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style:none; background-color:rgb(255,255,255); color:rgb(92,92,92)"> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(100,100,100); background-color:inherit">@Column</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">(updatable=</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(0,102,153); background-color:inherit"><strong>false</strong></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">)<wbr><wbr></wbr></wbr></span></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(0,102,153); background-color:inherit"><strong>public</strong></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(0,102,153); background-color:inherit"><strong>int</strong></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr>getAge()<wbr>{<wbr><wbr></wbr></wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(0,102,153); background-color:inherit"><strong>return</strong></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr>age;<wbr><wbr></wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr>}<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> </ol> </div> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> 我们在执行 Update方法会发现,age 属性 不会被更改</p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <div style="color:rgb(70,70,70); line-height:21.600000381469727px; font-family:Consolas,'Courier new',Courier,mono,serif; background-color:rgb(231,229,220); width:687.0499877929688px; overflow:auto; padding-top:1px; margin:18px 0px!important"> <div style="padding-left:45px"> <div style="padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(108,226,108)"> <strong>[java]</strong><wbr><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="view plain" style="text-decoration:none; color:rgb(62,115,160)">view plain</a><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="copy" style="text-decoration:none; color:rgb(62,115,160)">copy</a> <div></div> </wbr> </div> </div> <ol start="1" style="margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style:none; background-color:rgb(255,255,255); color:rgb(92,92,92)"> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit">Hibernate:<wbr><wbr><wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr>update<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Teacher<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr>set<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>birthday=?,<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>name=?,<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>title=?<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr>where<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>id=?<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> </ol> </div> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <span style="word-wrap:normal; word-break:normal; line-height:21.600000381469727px; color:rgb(255,0,0)">缺点:不灵活····</span></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> 2.第2种方法··使用XML中的<wbr><span style="word-wrap:normal; word-break:normal; line-height:21.600000381469727px; color:rgb(255,0,0)">dynamic-update="true"</span></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <div style="color:rgb(70,70,70); line-height:21.600000381469727px; font-family:Consolas,'Courier new',Courier,mono,serif; background-color:rgb(231,229,220); width:687.0499877929688px; overflow:auto; padding-top:1px; margin:18px 0px!important"> <div style="padding-left:45px"> <div style="padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(108,226,108)"> <strong>[xhtml]</strong><wbr><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="view plain" style="text-decoration:none; color:rgb(62,115,160)">view plain</a><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="copy" style="text-decoration:none; color:rgb(62,115,160)">copy</a> <div></div> </wbr> </div> </div> <ol start="1" style="margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style:none; background-color:rgb(255,255,255); color:rgb(92,92,92)"><li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(153,51,0); background-color:inherit"><strong>&lt;&lt;/span&gt;<span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">class</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:red; background-color:inherit">name</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">=</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"com.sccin.entity.Student"</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr><wbr></wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:red; background-color:inherit">table</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">=</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"student"</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:red; background-color:inherit">dynamic-update</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">=</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"true"</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">&gt;</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr><wbr></wbr></wbr></span></strong></span></span> </li></ol> </div> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <span style="word-wrap:normal; word-break:normal; line-height:21.600000381469727px; color:rgb(255,0,0)">OK,这样就不需要在字段上设置了。</span></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <span style="word-wrap:normal; word-break:normal; line-height:21.600000381469727px; color:rgb(255,0,0)">但这样的方法在Annotation中没有</span></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> 3.第三种方式:使用HQL语句(灵活,方便)</p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> 使用HQL语句修改数据</p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <div style="color:rgb(70,70,70); line-height:21.600000381469727px; font-family:Consolas,'Courier new',Courier,mono,serif; background-color:rgb(231,229,220); width:687.0499877929688px; overflow:auto; padding-top:1px; margin:18px 0px!important"> <div style="padding-left:45px"> <div style="padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(108,226,108)"> <strong>[java]</strong><wbr><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="view plain" style="text-decoration:none; color:rgb(62,115,160)">view plain</a><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="copy" style="text-decoration:none; color:rgb(62,115,160)">copy</a> <div></div> </wbr> </div> </div> <ol start="1" style="margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style:none; background-color:rgb(255,255,255); color:rgb(92,92,92)"> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(0,102,153); background-color:inherit"><strong>public</strong></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:rgb(0,102,153); background-color:inherit"><strong>void</strong></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr>update(){<wbr><wbr></wbr></wbr></wbr></span></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Session<wbr>session<wbr>=<wbr><wbr>HibernateUitl.getSessionFactory().getCurrentSession();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>session.beginTransaction();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Query<wbr>query<wbr>=<wbr>session.createQuery(<span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:blue; background-color:inherit">"update<wbr>Teacher<wbr>t<wbr>set<wbr>t.name<wbr>=<wbr>'yangtianb'<wbr>where<wbr>id<wbr>=<wbr>3"</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">);<wbr><wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>query.executeUpdate();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>session.getTransaction().commit();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr>}<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> </ol> </div> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> Hibernate 执行的SQL语句:</p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <div style="color:rgb(70,70,70); line-height:21.600000381469727px; font-family:Consolas,'Courier new',Courier,mono,serif; background-color:rgb(231,229,220); width:687.0499877929688px; overflow:auto; padding-top:1px; margin:18px 0px!important"> <div style="padding-left:45px"> <div style="padding:3px 8px 10px 10px; font-size:9px; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; color:silver; background-color:rgb(248,248,248); border-left-width:3px; border-left-style:solid; border-left-color:rgb(108,226,108)"> <strong>[xhtml]</strong><wbr><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="view plain" style="text-decoration:none; color:rgb(62,115,160)">view plain</a><a target="_blank" href="http://blog.csdn.net/Baykermr/article/details/5359913#" title="copy" style="text-decoration:none; color:rgb(62,115,160)">copy</a> <div></div> </wbr> </div> </div> <ol start="1" style="margin:0px 0px 1px 45px!important; padding:0px; border:none; list-style:none; background-color:rgb(255,255,255); color:rgb(92,92,92)"> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit">Hibernate:<wbr><wbr><wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr>update<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Teacher<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr>set<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:red; background-color:inherit">name</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">=</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:blue; background-color:inherit">'yangtianb'</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr><wbr><wbr></wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; background-color:rgb(248,248,248)"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr>where<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> <li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-width:0px 0px 0px 3px; border-style:none none none solid; border-left-color:rgb(108,226,108); list-style:decimal-leading-zero outside; color:inherit"> <span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:black; background-color:inherit"><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:red; background-color:inherit">id</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit">=</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; color:blue; background-color:inherit">3</span><span style="word-wrap:normal; word-break:normal; line-height:17.600000381469727px; margin:0px; padding:0px; border:none; background-color:inherit"><wbr><wbr></wbr></wbr></span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span> </li> </ol> </div> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> <wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:26px; font-size:14.399999618530273px; color:rgb(51,51,51); font-family:Arial"> 这样就只更新了我们更新的字段·····</p> </wbr>
分享到:
评论

相关推荐

    Hibernate更新某些字段

    如果我们直接使用 Session.update(Object o) 方法,Hibernate 会生成一个更新所有字段的 SQL 语句。这可能会导致性能问题,特别是当某些字段类型是文本类型且内容非常大时。 例如,在下面的代码中,我们使用 ...

    Hibernate update问题

    当你从数据库加载一个对象,修改其属性,然后调用`update()`方法,Hibernate会根据对象的状态自动执行相应的SQL UPDATE语句。然而,如果对象不在Session缓存中,`update()`方法可能会失效,因为Hibernate无法跟踪...

    hibernate实体映射文件字段设置默认值

    - **动态插入和更新**:`dynamic-insert`和`dynamic-update`属性允许Hibernate只插入或更新那些确实发生更改的字段。这对于避免不必要的数据库操作非常有用。 - **默认值类型**:默认值表达式的类型应与列的数据类型...

    spring+hibernate操作oracle的clob字段

    其中,`entity`对象包含了一个CLOB类型的属性,`assessRegDao`是一个接口,它的`update`方法由Hibernate实现,能够正确地处理CLOB字段的更新。 6. **注意事项** - 确保你的Oracle JDBC驱动版本与所使用的Oracle...

    spring+hibernate 解决大字段(clob)

    &lt;prop key="hibernate.hbm2ddl.auto"&gt;update &lt;prop key="hibernate.jdbc.batch_size"&gt;0 &lt;prop key="hibernate.connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider &lt;prop key="...

    Hibernate4实战 之第五部分:Hibernate的事务和并发

    ### Hibernate4实战之第五部分:Hibernate的事务与并发 #### 一、事务基础概念 **事务(Transaction)** 是一组逻辑上紧密相连的操作集合。在数据库领域,事务具备ACID特性: - **原子性(Atomicity)**:事务内的所有...

    Hibernate4实战资料

    它将一个属性映射为乐观锁的版本字段,每次更新时检查版本号,如果版本不匹配,则抛出并发控制异常,防止数据不一致。 除了这些核心注解,还有一些其他的注解如@Transient,用于标记非持久化属性,避免这些属性被...

    hibernate4框架学习笔记

    【hibernate4框架学习笔记】 Hibernate是一款强大的ORM(Object-Relational Mapping)框架,它在Java开发中扮演着至关重要的角色,通过提供对象与数据库之间的映射,解决了对象模型和关系模型之间的“阻抗不匹配”...

    Hibernate4中文帮助文档(中文教程)

    `save()`方法将瞬时对象变为持久化,`persist()`、`merge()`和`update()`用于更新对象,`delete()`用于删除对象。 六、查询语言(HQL) Hibernate提供了一种面向对象的查询语言HQL,类似于SQL但更贴近Java对象。HQL...

    Hibernate4总结文档

    《Hibernate4总结文档》 Hibernate4作为一款强大的Java对象关系映射框架,简化了数据库操作,使得开发者可以更专注于业务逻辑而不是数据库层面的细节。本文将深入探讨Hibernate4的配置和使用,帮助开发者更好地理解...

    hibernate动态更新

    如果在`&lt;class&gt;`映射中设置了`dynamic-update="true"`,Hibernate会在生成的SQL更新语句中只包含实际被修改的字段,而不是所有字段。这可以显著减少不必要的数据传输和数据库操作,从而提升性能。然而,`dynamic-...

    [PDF]Hibernate4(基本开发,入门,配置,CRUD)

    - **更新**(Update):修改已存在的数据库记录,并同步到数据库。 - **删除**(Delete):从数据库中移除记录。 #### Hibernate 对象状态 Hibernate 支持对象的多种状态管理,包括瞬时状态(Transient)、持久状态...

    hibernate4全注解例子

    **标题:“Hibernate4全注解例子”** 这篇文章主要讲解了如何在Java开发中使用Hibernate4框架,通过注解的方式进行数据库操作。Hibernate4是Java领域中广泛应用的对象关系映射(ORM)工具,它允许开发者使用面向...

    如何解决hibernate自动更新实体类的问题共5页.pd

    9. **使用乐观锁**:通过添加版本号或时间戳字段,利用Hibernate的乐观锁机制,在更新时检查数据是否被其他事务修改过,从而避免并发更新问题。 10. **使用SQL更新语句**:在某些情况下,可以使用原生的SQL更新语句...

    Hibernate操作数据库大字段的示例(附源码及详细开发使用方法)。

    1. **保存/更新大字段**:在保存或更新实体时,使用SessionFactory的`save()`或`update()`方法,Hibernate会自动处理大字段的存储。 ```java Session session = sessionFactory.openSession(); Transaction tx = ...

    jdbc+hibernate存取blob字段

    在Java的数据库编程中,...总结来说,无论是使用JDBC还是Hibernate,处理Oracle数据库的BLOB字段都需要了解其特殊性,尤其是BLOB字段的创建和更新过程。正确地操作BLOB字段,能够有效地存储和管理大容量的二进制数据。

    Hibernate,hibernate笔记

    `hibernate.hbm2ddl.auto`可以设置为"create-drop"、"create"、"update"或"validate",分别对应在启动时创建/删除数据库结构、创建数据库结构、更新数据库结构或验证数据库结构。 3. **HQL(Hibernate Query ...

    如何解决hibernate自动更新实体类的问题共5页.pdf.zip

    2. **设置属性不可变**:对于某些不应被修改的属性,可以在实体类中使用`@Immutable`注解,这样Hibernate会忽略这些属性的更改,不会执行更新操作。 3. **批处理更新**:如果需要批量更新,可以使用SQL语句或`...

    hibernate 的saveOrUpdate

    Hibernate提供了乐观锁和悲观锁策略来处理这种并发冲突,需要在实体类中添加版本字段或其他机制。 5. **节省代码**:使用`saveOrUpdate`可以减少代码量,因为无需先判断对象是否已存在,再分别调用`save`或`update`...

Global site tag (gtag.js) - Google Analytics