Spring Hibernate Errors and Solutions
Problem:
Hibernate Gives an Error for updating a column with a null value this column is a foreign key
Entity X has a resource in it
@JoinColumn(name = "resource_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Resource resource;
- not-null-property-references-a-null-or-transient-value
When the resource is null when we try to update in Hibernate 4.2.2 Final a error is given in Nullability.class
if ( checkability[i] && values[i]!= LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
final Object value = values[i];
if ( !nullability[i] && value == null ) {
//check basic level one nullablilty
throw new PropertyValueException(
"not-null property references a null or transient value",
persister.getEntityName(),
persister.getPropertyNames()[i]
);
}
Solution: Set @ManyToOne(optional = true)
@JoinColumn(name = "resource_id", referencedColumnName = "id")
@ManyToOne(optional = true)
private Resource resource;
Problem:
Hibernate does a select before updating entities and consumes memory for huge amount of data
Solution: Use @SelectBeforeUpdate(value = false)
@ManyToOne(optional = true)
private Resource resource;
Problem:
Hibernate does a select before updating entities and consumes memory for huge amount of data
Solution: Use @SelectBeforeUpdate(value = false)
Here when update() called, the entity got attached again. This always issues an UPDATE statement. This happens irrespective of weather the object has changed after detaching or not. One way to avoid this UPDATE statement while reattaching is setting the select-before-update= “true”. If this is set, hibernates tries to determine if the UPDATE needed by executing the SELECT statement by setting it to "true"
Comments
Post a Comment