- 浏览: 2791 次
- 来自: ...
最近访客 更多访客>>
文章分类
最新评论
-
jasongreen:
可以自己实现HashCodeBuilder<br ...
[求教]为什么我在使用HashCodeBuilder在one-to-many关系中出现Lazy异常 -
yes100:
我也遇到了,这个问题
[求教]为什么我在使用HashCodeBuilder在one-to-many关系中出现Lazy异常 -
surroad:
遇到类似的问题,请教高手
[求教]为什么我在使用HashCodeBuilder在one-to-many关系中出现Lazy异常
最近遇到一个奇怪的问题,我在实体类的基类中使用了org.apache.commons.lang.builder.HashCodeBuilder,然后在one-to-many关系映射(customer <---> order)中出现org.hibernate.LazyInitializationException: illegal access to loading collection异常。
小弟刚刚接触hibernate,这个问题找了两天才发现问题所在,但是仍然不知道为什么会这样,请大家不吝赐教。
环境:struts + hibernate3, hibernate2也试验过
异常:
org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:411)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:392)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:353)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:327)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:194)
at cz.model.BaseObject.hashCode(BaseObject.java:78)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:392)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:353)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:327)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:194)
at cz.model.BaseObject.hashCode(BaseObject.java:78)
at java.util.HashMap.hash(HashMap.java:261)...
Hibernate 3 和 2 都是这个异常
只是2的异常描述是:net.sf.hibernate.LazyInitializationException: cannot access loading collection
程序片断:
BO基类 cz.model.BaseObject
cz.model.Customer继承BaseObject
cz.model.Order继承BaseObject
映射文件
Customer.hbm.xml
Order.hbm.xml
DAO实现类中的方法
请大家帮我解答一下这个问题,谢谢。
小弟刚刚接触hibernate,这个问题找了两天才发现问题所在,但是仍然不知道为什么会这样,请大家不吝赐教。
环境:struts + hibernate3, hibernate2也试验过
异常:
org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:341)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:411)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:392)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:353)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:327)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:194)
at cz.model.BaseObject.hashCode(BaseObject.java:78)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:392)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:353)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:327)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:194)
at cz.model.BaseObject.hashCode(BaseObject.java:78)
at java.util.HashMap.hash(HashMap.java:261)...
Hibernate 3 和 2 都是这个异常
只是2的异常描述是:net.sf.hibernate.LazyInitializationException: cannot access loading collection
程序片断:
BO基类 cz.model.BaseObject
abstract public class BaseObject implements Serializable { public BaseObject(){} ... public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); } public boolean equals(Object o) { return EqualsBuilder.reflectionEquals(this, o); } //注释掉这个函数就不出现异常 public int hashCode() { return HashCodeBuilder.reflectionHashCode(this); }
cz.model.Customer继承BaseObject
public class Customer extends BaseObject implements Serializable { ... }
cz.model.Order继承BaseObject
public class Order extends BaseObject implements Serializable { ... }
映射文件
Customer.hbm.xml
<?xml version="1.0" encoding='UTF-8'?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping> <class name="cz.model.Customer" table="CUSTOMERS"> <id name="id" column="ID" type="long"> <generator class="increment"/> </id> ... <set name="orders" cascade="all-delete-orphan" inverse="true" lazy="true"> <key column="CUSTOMER_ID" /> <one-to-many class="cz.model.Order"/> </set> </class> </hibernate-mapping>
Order.hbm.xml
<hibernate-mapping> <class name="cz.model.Order" table="ORDERS"> <id name="id" type="long" column="ID"> <generator class="increment" /> </id> .... <many-to-one name="customer" column="CUSTOMER_ID" class="cz.model.Customer" cascade="save-update"/> </class> </hibernate-mapping>
DAO实现类中的方法
public Customer getCustomerById(Long customerId) throws AppException { Session session = HibernateUtil.getSession(); Transaction tx = null; try { tx = session.beginTransaction(); Query query = session.createQuery("from Customer c where c.id=:id"); query.setLong("id", customerId.longValue()); Customer customer = (Customer)query.uniqueResult(); Set orderset = customer.getOrders(); //在这里会抛出上面说的异常,如果在BaseObject.java中去掉 //public int hashCode() 方法就会正常,这是为什么呢?? System.out.println("orderset size=" + orderset.size()); tx.commit(); return customer; } catch (Exception ex) { HibernateUtil.rollbackTransaction(tx); AppException.appError(ex).printStackTrace(); throw AppException.appError(ex); } finally { HibernateUtil.closeSession(session); } }
请大家帮我解答一下这个问题,谢谢。
评论
3 楼
jasongreen
2007-03-14
可以自己实现HashCodeBuilder<br/>
<br/>
<div class='code_title'>java 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-j' start='1'>
<li class='alt'><span><span class='keyword'>import</span><span> java.lang.reflect.Array; </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span><span class='keyword'>public</span><span> </span><span class='keyword'>class</span><span> HashCodeBuilder { </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder() { </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>private</span><span> </span><span class='keyword'>int</span><span> result = </span><span class='number'>17</span><span>; </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>boolean</span><span> field) { </span></span></li>
<li class='alt'><span> result = <span class='number'>37</span><span> * result + (field ? </span><span class='number'>1</span><span> : </span><span class='number'>0</span><span>); </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>byte</span><span> field) { </span></span></li>
<li class=''><span> result = <span class='number'>37</span><span> * result + (</span><span class='keyword'>int</span><span>) field; </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>char</span><span> field) { </span></span></li>
<li class='alt'><span> result = <span class='number'>37</span><span> * result + (</span><span class='keyword'>int</span><span>) field; </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>short</span><span> field) { </span></span></li>
<li class=''><span> result = <span class='number'>37</span><span> * result + (</span><span class='keyword'>int</span><span>) field; </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>int</span><span> field) { </span></span></li>
<li class='alt'><span> result = <span class='number'>37</span><span> * result + field; </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>long</span><span> field) { </span></span></li>
<li class=''><span> result = <span class='number'>37</span><span> * result + (</span><span class='keyword'>int</span><span>) (field ^ (field >>> </span><span class='number'>32</span><span>)); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>float</span><span> field) { </span></span></li>
<li class='alt'><span> result = <span class='number'>37</span><span> * result + Float.floatToIntBits(field); </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>double</span><span> field) { </span></span></li>
<li class=''><span> append(Double.doubleToLongBits(field)); </span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder append(Object field) { </span></span></li>
<li class='alt'><span> <span class='keyword'>if</span><span>(field == </span><span class='keyword'>null</span><span>) </span></span></li>
<li class=''><span> result = <span class='number'>0</span><span>; </span></span></li>
<li class='alt'><span> <span class='keyword'>else</span><span> </span><span class='keyword'>if</span><span> (field.getClass().isArray()) { </span></span></li>
<li class=''><span> <span class='keyword'>for</span><span> (</span><span class='keyword'>int</span><span> i = Array.getLength(field) - </span><span class='number'>1</span><span>; i >= </span><span class='number'>0</span><span>; i--) { </span></span></li>
<li class='alt'><span> append(Array.get(field, i)); </span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> } <span class='keyword'>else</span><span> </span></span></li>
<li class=''><span> append(field.hashCode()); </span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> </span><span class='keyword'>int</span><span> toHashCode() { </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> result; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> </span><span class='keyword'>int</span><span> hashCode() { </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> result; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> String toString() { </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> String.valueOf(result); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span>} </span></li>
</ol>
</div>
<br/>
<div class='code_title'>java 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-j' start='1'>
<li class='alt'><span><span class='keyword'>import</span><span> java.lang.reflect.Array; </span></span></li>
<li class=''><span> </span></li>
<li class='alt'><span><span class='keyword'>public</span><span> </span><span class='keyword'>class</span><span> HashCodeBuilder { </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder() { </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>private</span><span> </span><span class='keyword'>int</span><span> result = </span><span class='number'>17</span><span>; </span></span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>boolean</span><span> field) { </span></span></li>
<li class='alt'><span> result = <span class='number'>37</span><span> * result + (field ? </span><span class='number'>1</span><span> : </span><span class='number'>0</span><span>); </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>byte</span><span> field) { </span></span></li>
<li class=''><span> result = <span class='number'>37</span><span> * result + (</span><span class='keyword'>int</span><span>) field; </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>char</span><span> field) { </span></span></li>
<li class='alt'><span> result = <span class='number'>37</span><span> * result + (</span><span class='keyword'>int</span><span>) field; </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>short</span><span> field) { </span></span></li>
<li class=''><span> result = <span class='number'>37</span><span> * result + (</span><span class='keyword'>int</span><span>) field; </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>int</span><span> field) { </span></span></li>
<li class='alt'><span> result = <span class='number'>37</span><span> * result + field; </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>long</span><span> field) { </span></span></li>
<li class=''><span> result = <span class='number'>37</span><span> * result + (</span><span class='keyword'>int</span><span>) (field ^ (field >>> </span><span class='number'>32</span><span>)); </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>float</span><span> field) { </span></span></li>
<li class='alt'><span> result = <span class='number'>37</span><span> * result + Float.floatToIntBits(field); </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> HashCodeBuilder append(</span><span class='keyword'>double</span><span> field) { </span></span></li>
<li class=''><span> append(Double.doubleToLongBits(field)); </span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> HashCodeBuilder append(Object field) { </span></span></li>
<li class='alt'><span> <span class='keyword'>if</span><span>(field == </span><span class='keyword'>null</span><span>) </span></span></li>
<li class=''><span> result = <span class='number'>0</span><span>; </span></span></li>
<li class='alt'><span> <span class='keyword'>else</span><span> </span><span class='keyword'>if</span><span> (field.getClass().isArray()) { </span></span></li>
<li class=''><span> <span class='keyword'>for</span><span> (</span><span class='keyword'>int</span><span> i = Array.getLength(field) - </span><span class='number'>1</span><span>; i >= </span><span class='number'>0</span><span>; i--) { </span></span></li>
<li class='alt'><span> append(Array.get(field, i)); </span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> } <span class='keyword'>else</span><span> </span></span></li>
<li class=''><span> append(field.hashCode()); </span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> </span><span class='keyword'>this</span><span>; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='keyword'>public</span><span> </span><span class='keyword'>int</span><span> toHashCode() { </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> result; </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class='alt'><span> <span class='keyword'>public</span><span> </span><span class='keyword'>int</span><span> hashCode() { </span></span></li>
<li class=''><span> <span class='keyword'>return</span><span> result; </span></span></li>
<li class='alt'><span> } </span></li>
<li class=''><span> </span></li>
<li class='alt'><span> <span class='annotation'>@Override</span><span> </span></span></li>
<li class=''><span> <span class='keyword'>public</span><span> String toString() { </span></span></li>
<li class='alt'><span> <span class='keyword'>return</span><span> String.valueOf(result); </span></span></li>
<li class=''><span> } </span></li>
<li class='alt'><span> </span></li>
<li class=''><span>} </span></li>
</ol>
</div>
2 楼
yes100
2007-02-16
我也遇到了,这个问题
1 楼
surroad
2007-02-07
遇到类似的问题,请教高手
相关推荐
在Java项目中,将Apache Commons Lang的jar包添加到项目的类路径中,就可以直接使用其中提供的类和方法。 在标签中提到了"commons.lang jar包",这表明了这个资源包的核心是`commons-lang.jar`,在更现代的版本中,...
在本篇文章中,我们将深入探讨Apache Commons Lang 2.6的主要特性、使用场景以及如何将其集成到Java项目中。 Apache Commons Lang 2.6包含了许多有用的类和方法,主要分为以下几个核心模块: 1. **字符串处理**:...
在"commons-lang3-3.10-bin.tar.gz"和"commons-lang3-3.10-bin.zip"中,包含了编译好的二进制版本,可以直接在项目中使用。而"commons-lang3-3.10-src.tar.gz"和"commons-lang3-3.10-src.zip"则是源码包,供开发者...
在实际开发中,使用这些Builder类可以减少错误并提高代码质量。例如,`HashCodeBuilder`和`EqualsBuilder`可以确保在添加或删除字段时,`equals()`和`hashCode()`的实现不会忘记更新。`ToStringBuilder`则可以帮助...
3. **对象工具**:`ObjectUtils`提供了诸如`firstNonNull()`方法,可以安全地获取多个可能为null的对象中的第一个非null值,而`EqualsBuilder`和`HashCodeBuilder`则帮助我们构建更加健壮的equals()和hashCode()方法...
5. **数学计算**:`NumberUtils` 包含了一些关于数值的静态方法,如 `toInt()`、`toDouble()` 等,可以安全地将字符串转换为数字,处理空值时不会抛出异常。 6. **反射工具**:`ReflectionUtils` 提供了关于反射的...
《Apache Commons Lang 3.7在Java Web开发中的应用》 Apache Commons Lang是Apache软件基金会提供的一个Java工具包,专门处理一些Java语言的核心库没有涵盖的功能。其中,`commons-lang3-3.7`是Lang组件的一个版本...
### Apache Commons 包最新使用指南(2009年版)关键知识点解析 #### 一、概述 Apache Commons 是一个由 Apache 软件基金会维护的一系列 Java 工具类库,旨在为 Java 开发者提供一系列可复用的组件和服务。本指南...
7. **异常处理**:`ExceptionUtils` 提供了处理和包装异常的功能,简化异常处理代码。 8. **其他工具类**:`ArrayUtils` 对数组操作提供了扩展,如添加、删除、查找和转换等。`CharSetUtils` 和 `Charsets` 用于...
`NumberUtils`类提供了一些关于数字的辅助方法,比如`toInt()`, `toDouble()`, `toLong()`等,它们可以将各种类型的数值转换为整型、浮点型或长整型。此外,`RandomUtils`类提供了线程安全的随机数生成方法,适用于...
《深入解析`common-lang3.jar`:Java编程中的实用工具库》 在Java开发中,高效、便捷的工具类库是提升开发效率的关键。`common-lang3.jar`就是这样一个广泛使用的工具库,它包含了大量实用的Java语言工具类,极大地...
`ObjectUtils`主要用于处理Java对象,尤其在处理null值时显得尤为重要。其关键特性有: - **对象比较与合并**:提供了比较两个对象是否相等的方法(`equals`),即使其中一个或两个对象为null也能正常处理。 - **...
在Maven项目中,我们可以将Apache Commons Lang作为依赖引入,这样就可以在项目中直接使用这些工具类,提高代码的可读性和效率。通过Maven的POM.xml文件,我们可以指定依赖的版本号,如`<dependency>`标签中包含的`...
在Java编程中,HashMap是一种常用的集合类,它提供了一种快速存取键值对的方式。HashMap基于哈希表的原理实现,其内部结构是数组加链表,JDK1.8之后如果链表长度超过8则会转换为红黑树,以优化查找性能。本文将深入...
在实践中,为了代码的可读性和一致性,可以考虑使用Apache Commons Lang库的EqualsBuilder和HashCodeBuilder,或者使用Lombok库的@EqualsAndHashCode注解,它们可以帮助我们更方便地生成这些方法。 总的来说,重写...
在软件开发过程中,特别是在J2EE领域中,Hibernate作为一种流行的ORM(Object-Relational Mapping)框架被广泛使用。ORM框架的主要作用是将关系型数据库中的数据映射到对象模型上,从而简化了数据的持久化操作。在...
Apache Commons是一系列开源的Java通用工具类库,提供了很多常用的工具类和方法,可以在项目中简化代码,提高开发效率。其内容覆盖了字符串操作、数据类型转换、集合处理、数学计算、日期和时间处理、Bean操作等众多...
通过以上介绍,我们可以看出Apache Commons项目中的各个库都提供了非常实用的功能,可以帮助开发者更加高效地编写代码。无论是字符串处理、日期时间操作还是集合管理,这些工具类都能极大地提高开发效率并减少出错的...
在关系型数据库设计中,经常会出现使用多个字段组合起来作为主键的情况,这种类型的主键被称为复合主键。而在Java领域,尤其是使用Hibernate框架进行持久化操作时,复合主键的应用变得尤为重要。本文将详细介绍如何...