﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-无聊人士-随笔分类-Hibernate</title><link>http://www.blogjava.net/mmwy/category/4887.html</link><description>wuyu</description><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 12:19:21 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 12:19:21 GMT</pubDate><ttl>60</ttl><item><title>hibernate.hbm2ddl.auto与import.sql</title><link>http://www.blogjava.net/mmwy/archive/2006/10/31/78187.html</link><dc:creator>mmwy</dc:creator><author>mmwy</author><pubDate>Mon, 30 Oct 2006 16:32:00 GMT</pubDate><guid>http://www.blogjava.net/mmwy/archive/2006/10/31/78187.html</guid><wfw:comment>http://www.blogjava.net/mmwy/comments/78187.html</wfw:comment><comments>http://www.blogjava.net/mmwy/archive/2006/10/31/78187.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mmwy/comments/commentRss/78187.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mmwy/services/trackbacks/78187.html</trackback:ping><description><![CDATA[笔记一下：<br /><br />设hibernate.hbm2ddl.auto为update/create-drop/create后，在classpath中扔一个/import.sql进去，hibernate启动时就会执行import.sql的内容。<br /><br />11860 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaExport  - Running hbm2ddl schema export<br />11860 [main] DEBUG org.hibernate.tool.hbm2ddl.SchemaExport  - import file not found: /import.sql<br />11875 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaExport  - exporting generated schema to database<br /><img src ="http://www.blogjava.net/mmwy/aggbug/78187.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mmwy/" target="_blank">mmwy</a> 2006-10-31 00:32 <a href="http://www.blogjava.net/mmwy/archive/2006/10/31/78187.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql 3.23.58 charset设置对blob字段操作的影响</title><link>http://www.blogjava.net/mmwy/archive/2006/10/12/74800.html</link><dc:creator>mmwy</dc:creator><author>mmwy</author><pubDate>Thu, 12 Oct 2006 07:54:00 GMT</pubDate><guid>http://www.blogjava.net/mmwy/archive/2006/10/12/74800.html</guid><wfw:comment>http://www.blogjava.net/mmwy/comments/74800.html</wfw:comment><comments>http://www.blogjava.net/mmwy/archive/2006/10/12/74800.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mmwy/comments/commentRss/74800.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mmwy/services/trackbacks/74800.html</trackback:ping><description><![CDATA[最近在“玩”hibernate Annotation，弄了个Attachment保存进数据库的测试，附件内容保存在content属性里面。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">  @Lob<br />  @Column(columnDefinition </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">LongBlob</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[] getContent() {<br />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> content;<br />  }</span></div>一开始，配置mysql jdbc url如下<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">jdbc.url            </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">    jdbc:mysql://localhost/test\<br />                            ?useUnicode</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">true\<br />                            &amp;characterEncoding</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">gbk</span><span style="color: rgb(0, 0, 0);"></span></div>一测试，报错<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">Caused by: java.sql.BatchUpdateException: Syntax error or access violation message from server: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">You have an error in your SQL syntax near ''D0CF11E0A1B11AE1000000000000000000000000000000003E000300FEFF0900060000000000000' at line 1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:</span><span style="color: rgb(0, 0, 0);">1540</span><span style="color: rgb(0, 0, 0);">)</span></div>同样的语句，直接在mysql命令行下运行就没问题，偏偏jdbc上就有这臭毛病。换jdbc driver版本，改@Lob为 @Type(type = "org.springframework.orm.hibernate3.support.BlobByteArrayType")，改hibernate配置（比如hibernate.jdbc.use_streams_for_binary true），甚至是直接用jdbc来insert，乱七八糟折腾半天，问题照旧。最后只好用上“歪”招，把byte[]配成String，在保存的时候把byte[]保存成hex String格式，取的时候再解码回来。<br /><br />歪招终归是歪招，这两天老为这东西心烦，晚上吃饭的时候无意中想起charset的问题，把代码捡回来再测试了一下，问题解决，哈哈！<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">jdbc.url            </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">    jdbc:mysql://localhost/mmwy_blog\<br />                            ?useUnicode</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">true\<br />                            &amp;characterEncoding</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">utf-</span><span style="color: rgb(0, 0, 0);">8</span></div>如果设成iso-8859-1、utf-8,保存一点问题都没有，换用gbk、gb2312、big5之类的字符集，问题就出来了。<br /><br /><img src ="http://www.blogjava.net/mmwy/aggbug/74800.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mmwy/" target="_blank">mmwy</a> 2006-10-12 15:54 <a href="http://www.blogjava.net/mmwy/archive/2006/10/12/74800.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate annotations试用</title><link>http://www.blogjava.net/mmwy/archive/2006/10/12/74792.html</link><dc:creator>mmwy</dc:creator><author>mmwy</author><pubDate>Thu, 12 Oct 2006 07:38:00 GMT</pubDate><guid>http://www.blogjava.net/mmwy/archive/2006/10/12/74792.html</guid><wfw:comment>http://www.blogjava.net/mmwy/comments/74792.html</wfw:comment><comments>http://www.blogjava.net/mmwy/archive/2006/10/12/74792.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/mmwy/comments/commentRss/74792.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/mmwy/services/trackbacks/74792.html</trackback:ping><description><![CDATA[最近开始尝试hibernate annotations，终于成功的将手上一个小应用转为annotations ：）<br /><br /><b>1、spring orm support</b><br />与原来使用LocalSessionFactoryBean相比，变动不大（AnnotationSessionFactoryBean本来就是从LocalSessionFactoryBean类继承过来的嘛）<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);">   </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(128, 0, 0);">        </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="sessionFactory"</span><span style="color: rgb(255, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(255, 0, 0);">        class</span><span style="color: rgb(0, 0, 255);">="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"</span><span style="color: rgb(255, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(255, 0, 0);">        parent</span><span style="color: rgb(0, 0, 255);">="AbstractSessionFactory"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="annotatedClasses"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">list</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">xxx.xxx.xxx.domain.Account</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">list</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">bean<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(128, 0, 0);">        </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="AbstractSessionFactory"</span><span style="color: rgb(255, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(255, 0, 0);">        class</span><span style="color: rgb(0, 0, 255);">="org.springframework.orm.hibernate3.LocalSessionFactoryBean"</span><span style="color: rgb(255, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(255, 0, 0);">        abstract</span><span style="color: rgb(0, 0, 255);">="true"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(128, 0, 0);">            </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="dataSource"</span><span style="color: rgb(255, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(255, 0, 0);">            ref</span><span style="color: rgb(0, 0, 255);">="DataSource"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="hibernateProperties"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">props</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">prop </span><span style="color: rgb(255, 0, 0);">key</span><span style="color: rgb(0, 0, 255);">="hibernate.dialect"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">${hibernate.dialect}</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">prop</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">prop </span><span style="color: rgb(255, 0, 0);">key</span><span style="color: rgb(0, 0, 255);">="hibernate.show_sql"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">${hibernate.show_sql}</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">prop</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">prop </span><span style="color: rgb(255, 0, 0);">key</span><span style="color: rgb(0, 0, 255);">="hibernate.hbm2ddl.auto"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">${hibernate.hbm2ddl.auto}</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">prop</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">prop </span><span style="color: rgb(255, 0, 0);">key</span><span style="color: rgb(0, 0, 255);">="hibernate.cache.use_query_cache"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">${hibernate.cache.use_query_cache}</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">prop</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">prop </span><span style="color: rgb(255, 0, 0);">key</span><span style="color: rgb(0, 0, 255);">="hibernate.cache.provider_class"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">${hibernate.cache.provider_class}</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">prop</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">props</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">property</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">property<br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(128, 0, 0);">            </span><span style="color: rgb(255, 0, 0);">name</span><span style="color: rgb(0, 0, 255);">="lobHandler"</span><span style="color: rgb(255, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(255, 0, 0);">            ref</span><span style="color: rgb(0, 0, 255);">="DefaultLobHandler"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">bean</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><b>2、id的配置</b><br />非常简单，在id的getter上面加个“@Id”就可以了。此时采用的id策略是javax.persistence.GenerationType.AUTO，也可以再加上“@GeneratedValue(generator =GenerationType.IDENTITY|GenerationType.SEQUENCE|GenerationType.TABLE)”换成其它策略。<br />我的应用采用的是hibernate的uuid策略，就不得不在这儿使用hibernate的扩展了<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">  @Id<br />  @Column(length </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">32</span><span style="color: rgb(0, 0, 0);">)<br />  @GeneratedValue(generator </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">system-uuid</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />  @GenericGenerator(name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">system-uuid</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, strategy </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">uuid</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)</span></div><br /><b>3、级联策略</b><br />在ejb3-persistence.jar中只定义了ALL、MERGE、PERSIST、REFRESH、REMOVE，比较恶心的就是，删除对象的时候，并不会级联删除关联对象，而是用update xx set parent_id=null where parent_id=?这类语句把关系干掉了事。不得已，在这儿用了hibernate的DELETE_ORPHAN。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">  @OneToMany(targetEntity </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Attachment.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">)<br />  @Cascade(value </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {org.hibernate.annotations.CascadeType.DELETE_ORPHAN,<br />      org.hibernate.annotations.CascadeType.ALL})<br />  @JoinColumn(name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">info_id</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)</span></div><b>4、CACHE</b><br />ejb3-persistence.jar里面没有找到cache的配置，继续请出hibernate来干活<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.hibernate.annotations.Cache;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.hibernate.annotations.CacheConcurrencyStrategy;<br /><br />@Entity<br />@Table(name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">T_INFO</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />@Cache(usage </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)</span></div><b>5、自定义字段类型</b><br />我的POJO中有一个private String content;的属性，按ejb3配成@Lob后，被处理成了text类型，text 64k的存储容量还是比较可怜了。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">  @Lob<br />  @Column(columnDefinition </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">LongText</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)</span></div><br /><img src ="http://www.blogjava.net/mmwy/aggbug/74792.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/mmwy/" target="_blank">mmwy</a> 2006-10-12 15:38 <a href="http://www.blogjava.net/mmwy/archive/2006/10/12/74792.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>