Home Shared column on two relationships causing null in both
Reply: 0

Shared column on two relationships causing null in both

user1550 Published in March 23, 2018, 10:17 pm

I had this entity that relationships with another two, but there is a column in common.

@Table(name = "RH_EVENT")
public class RhEvent implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column(name = "ESOC_ID", insertable=false, updatable=false)   
    private long esocId;

    @JoinColumn(name="ESOC_ID_COMPANY", insertable=false, updatable=false) 
    private Company company;

       @JoinColumn(name="ESOC_ID_COMPANY", referencedColumnName="BRAN_ID_COMPANY", updatable=false, insertable= false),
       @JoinColumn(name="ESOC_ID_BRANCH", referencedColumnName="BRAN_ID_BRANCH", nullable=true, updatable=false, insertable= false),
    private Branch branch;

    private String esocFlag;

    //more fields

The column is ESOC_ID_COMPANY, to query information everything is working fine. But when i update ESOC_FLAG field, making:

RhEvent myEvent = entityManager.find(RhEvent.class,1l);

JPA update ESOC_ID_COMPANY with null value, i believe the problem is that column BRAN_ID_BRANCH is null and branch relationship finds null, so all columns of relationship are updated.

How i solve this? The table came from a legacy system, so i cannot change relationships.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.294625 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO