当列值为null时,hibernate没有结果

时间:2015-08-26 12:01:44

标签: java mysql hibernate

我有一个包含多个pk的表,而某些列可以具有空值

当所有列都有来自休眠的完整结果集的数据时。

当一个或多个列具有空值时,问题出现了,那么hibernate没有加载数据。

这是表格架构

 @Entity
 @IdClass(ConfigurationChanged.class)
 @Table(name="configuration_changed")
 @NamedQuery(name="ConfigurationChanged.findAll", query="SELECT c FROM ConfigurationChanged c")
public class ConfigurationChanged implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name="column_name", length=45)
private String columnName;

@Id
@Column(nullable=false)
private Timestamp date;

@Column(name="new_value", length=45, nullable=true)
private String newValue;

@Column(name="old_value", length=45, nullable=true)
private String oldValue;

@Id
@Lob
@Column(nullable=false)
private String pk;

@Id
@Lob
@Column(name="table_name", nullable=false)
private String tableName;

@Column(length=1)
private String type;

//bi-directional many-to-one association to Box
@ManyToOne
@JoinColumn(name="idbox", nullable=false)
private Box box;

// getters and setters ...

这是我模特的代码:

    @Override
public int hashCode()
{
    final int prime = 31;
    int result = 1;

    result = prime * result + ((columnName == null) ? 0 : columnName.hashCode());
    result = prime * result + ((date == null) ? 0 : date.hashCode());
    result = prime * result + ((pk == null) ? 0 : pk.hashCode());
    result = prime * result + ((tableName == null) ? 0 : tableName.hashCode());
    result = prime * result + ((box == null || box.getId() == null) ? 0 : (int) (box.getId() ^ (box.getId() >>> 32)));
    result = prime * result + ((type == null) ? 0 : type.hashCode());
    result = prime * result + ((newValue == null) ? 0 : newValue.hashCode());
    result = prime * result + ((oldValue == null) ? 0 : oldValue.hashCode());


    return result;
}

当我把hibernate制作的查询放在mysql shell上时,我没有发现任何问题并得到了结果

我缺少什么?

感谢您的帮助(对不起我的英语)

我发现问题但不是根本原因

问题来自我覆盖的hashCode方法

--cloudprovider=openstack

0 个答案:

没有答案