Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Eclipselink support for one-way ManyToOne relationships?

I'm seeing something strange with this configuration:

Two entities:

@Entity
public class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="person_id")
    private Long id;

    private String name;
    //...
}

@Entity
public class Phone {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "phone_id")
    private Long phoneId;

    private String number;

    @ManyToOne(cascade = CascadeType.ALL, optional=false)
    @JoinColumn(name = "person_id")
    private Person person;
}


And using them with:

Person p = new Person();
p.setName("A Person");

Phone ph1 = new Phone();
ph1.setNumber("212-1111");
ph1.setPerson(p);

Phone ph2 = new Phone();
ph2.setNumber("313-4444");
ph2.setPerson(p);

generates the following sql:

INSERT INTO PERSON (NAME) VALUES (?)
bind => [A Person]
INSERT INTO PHONE (NUMBER, PERSON_person_id) VALUES (?, ?)
bind => [212-1111, 1]

INSERT INTO PERSON (NAME) VALUES (?)
bind => [A Person]
INSERT INTO PHONE (NUMBER, PERSON_person_id) VALUES (?, ?)
bind => [313-4444, 2]


I tried to save/merge the Person right after creation, but that only gave me an extra insert into the person table:

INSERT INTO PERSON (NAME) VALUES (?)
bind => [A Person]

INSERT INTO PERSON (NAME) VALUES (?)
bind => [A Person]
INSERT INTO PHONE (NUMBER, PERSON_person_id) VALUES (?, ?)
bind => [212-1111, 2]

INSERT INTO PERSON (NAME) VALUES (?)
bind => [A Person]
INSERT INTO PHONE (NUMBER, PERSON_person_id) VALUES (?, ?)
bind => [313-4444, 3]

When I debug and inspect the objects, I can see that the phone object has the _persistence_* woven fields, but the person object does not. Is there a way to force eclipse to weave that class? 



Am I missing something in my declarations? Does Eclipselink not support this style of relationships? I tried the same thing with hibernate, and it does the right thing.
Do I need some other annotation? 

Using spring-boot 2.1.3, eclipselink 2.7.4, runtime-weaving.


Thanks,
Glenn

Back to the top