---
title: "多线程/Hibernate/调用属性时候 间隔发生的诡异问题:debug能看到属性值,但访问属性却nullpointerEx(应用产品问题)"
author: "fanyo"
date: "2010-10-25T16:04:12Z"
tags: []
categories: ["企业架构"]
slug: "hibernate-debug-nullpointerex"
draft: false
lastmod: "2010-10-25T16:07:09Z"
id: 793319
url: "https://fanyo.iteye.com/blog/793319"
---

当调用一个命令reset operations 时候启动4个线程 做一些操作.  
这个重复命令执行大约运行七八次,assetMove.getAssetType().getType()就会返回一次nullpointerException.

```
    public TmEquipmentType getAssetType() {
        return (_asset != null) ? _asset.getType() : _containerPlanEquipmentType.getEquipmentType();
    }
```

TmAssetMoveImpl.hbm.xml  
        &lt;many-to-one name="containerPlanEquipmentType"

                    

```
class="com.redprairie.tm.core.TmContainerPlanEquipmentTypeImpl" >
            <column name="container_plan_equip_id" />
        </many-to-one>
```

TmContainerPlanEquipmentTypeImpl.hbm.xml  
       &lt;many-to-one name="equipmentType"

                    

```
class="com.redprairie.tm.assets.TmEquipmentTypeImpl">
            <column name="equip_typ" />
       </many-to-one>
```

我改了下assetMove.getAssetType() 进行debug, assetMove.getAssetType()明明能看到值, 但是调用它的属性的时候就会Nullpointer.

![](/admin/blogs/793319/null.GIF) 起初运行 五六次命令会出现一次异常,  后来改来将

```
containerPlanEquipmentType.getEquipmentType()
```

set和get方法同步一下  运行一百次命令出现一次异常.

 

难道和hibernate的lazy 或者什么其他设置有关?