Eclipselink持久关系表创建选择

时间:2017-09-11 15:10:42

标签: java eclipselink persistence

我有这个实体:

@Entity
@Table(name = "VEHICULE")
public class Vehicule {

    @Id
    @Column(nullable = false, name = "NUMERO")
    private String numero;

@Entity
@Table(name = "RAME_VEHICULE")
public class RameVehicule {

    @ManyToOne
    @JoinColumn(name = "VEHICULE_NUMERO")
    private Vehicule vehicule;

    @ManyToOne
    @JoinColumn(name = "RAME_ID")
    private Rame rame;

}

@Entity
@Table(name = "RAME")
public class Rame {

 @Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "RAME_SEQ")
@SequenceGenerator(name = "RAME_SEQ", sequenceName = "RAME_SEQ", allocationSize = 1)
@Column(nullable = false, name = "ID")
private Long id;

@Column(name = "NUMERO")
private String numero;

当我创建一个新的RameVehicule时,当我想在设置Rame和Vehicule(rame和vehicule已经存在于数据库中)之后保存实体时,我这样做:

  entityManager.persist(rameVehicule);

在postgresql.log中我看到:

durée : 2.000 ms, lien S_10 : select nextval('RAME_VEHICULE_SEQ')
exécute S_10: select nextval('RAME_VEHICULE_SEQ')
durée : 6.000 ms
exécute S_1: SELECT ID FROM RAME WHERE (ID = $1)
:  paramètres : $1 = '3059211'
durée : 1.000 ms
exécute S_9: SELECT NUMERO FROM VEHICULE WHERE (NUMERO = $1)
:  paramètres : $1 = 'Z27717'
durée : 1.000 ms
exécute S_13: INSERT INTO RAME_VEHICULE (ID, DATE_DEBUT_VALIDITE, DATE_FIN_VALIDITE, RANG, RAME_ID, VEHICULE_NUMERO) VALUES ($1, $2, $3, $4, $5, $6)
:  paramètres : $1 = '69807', $2 = '2017-02-13 06:03:00', $3 = '2017-02-13 06:08:00', $4 = '0', $5 = '3059211', $6 = 'Z27717'
durée : 1.000 ms

为什么Eclipselink在插入之前会在vehicule和rame上生成select?

怎么能避免这个?

谢谢!

0 个答案:

没有答案