-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Issue with updating unidirectional multi-column graph
PostPosted: Tue Aug 12, 2014 12:31 pm 
Newbie

Joined: Tue Aug 12, 2014 11:57 am
Posts: 1
I have 2-level deep all-unidirectional object hierarchy with collections and auditing that I am trying to save using hibernate and envers. The code is failing to save it with a NPE in envers if I use saveOrUpdate, or a NonUniqueObjectException if I try to save using merge. This looks like an issue with save of multi-column join, with a parent of two primary columns inserting into a child of three primary columns, but I am not sure.

Here is my code:

First Level Class Borrower with two columns in primary key:
Code:
@Audited
@Entity
public class Borrower implements Serializable{

    @Id
    @Column(name = "BWR_ID", nullable = false)
    private String borrowerId;
   
    @Id
    @Column(name = "LOAN_ID")
    String loanId;
   
    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumns({
        @JoinColumn(name = "LOAN_ID"),
        @JoinColumn(name = "BWR_ID")})
    @NotAudited
    Set<BorrowerRating> borrowerRatings;

    ... getters, setters and other fields
}


Second Level class BorrowerRating, with an additional column as primary key
Code:
@Audited
@Entity
public class BorrowerRating implements Serializable{
    @Id
    @Column(name = "LOAN_ID")
    private String loanId;

    @Id
    @Column(name = "BWR_ID", nullable = false)
    private String borrowerId;

    @Id
    @Column(name = "RATING_EFECTIVE_DT")
    private String ratingEffectiveDate;

    ... getters, setters and other fields
}


In my test, if I try to "update" graph using merge, I get

Quote:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.a.b.c.d.BorrowerRating#BorrowerRating [loanId=null, borrowerId=null, ratingEffectiveDate=null]]


Debugging shows it identified BorrowerRating as detached object and while creating clone, created an empty object (as evident above with all values null), even though my original object has all values populated. When it encountered the second object from set, it created another empty object - and obviously resulted in NonUniqueObjectException.

Instead, if I try to update it using saveOrUpdate, I get:
Quote:
java.lang.NullPointerException
at org.hibernate.envers.event.EnversPostUpdateEventListenerImpl.postUpdateDBState(EnversPostUpdateEventListenerImpl.java:86)
at org.hibernate.envers.event.EnversPostUpdateEventListenerImpl.onPostUpdate(EnversPostUpdateEventListenerImpl.java:53)
at org.hibernate.action.internal.EntityUpdateAction.postUpdate(EntityUpdateAction.java:255)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:212)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)


Neither of these make any sense to me. Can someone help me understand what am I doing wrong here? TIA!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.