#StackBounty: #hibernate #spring-boot #spring-data-jpa #hibernate-envers Hibernate Envers doesn't save referenced column value in c…

Bounty: 50

Here’s the code for 2 entities, machine and device.

@Audited
@Entity(name = "device")
@Table(name = "device")
public class Device {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    @JoinColumn(name = "machineCode", referencedColumnName = "machineCode")
    private Machine machine;

}

@Audited
@Entity(name = "machine")
@Table(name = "machine")
public class Machine {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String machineCode;

}

Now, when i save the device entity. The machineCode column (in the auditing table of device) gets the value of id and not the corresponding machineCode from machine’s domain object.
I am not sure if there is anything wrong with the code or not. Thanks in advance.

PS – there are other intermingled entities attached to machine entity as well. So, adding @OneToMany is not required or i should say, it would be an overhead.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.