openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ɓukasz Budnik <lukasz.bud...@gmail.com>
Subject 2 @OneToOne mappings, 1st one gets nulls, 2nd gets 1st's values
Date Tue, 06 Apr 2010 21:10:51 GMT
Hi all,

I'm using OpenJPA 2.1.3 which is shipped with Apache Geronimo 2.1.3.

In my application I have a problem with persisting 2 @OneToOne objects.

The story is... I have three entities. Process which may have many
Partners. In addition each Process and its Partner have Flags object.
Flags is a single entity with a fixed amount of columns.

I map Process -> Flags and Partner -> Flags relationships to
one-to-one mappings and Process -> Partner as one-to-many:

public class Process implements Serializable {
	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
	@JoinColumn(name="ID_FLAGS", nullable=false)
	private Flags flags;

	@OneToMany(targetEntity = org.xx.Partner.class, mappedBy = "process",
cascade = CascadeType.PERSIST)
	private List<Partner> partners = new ArrayList<Partners>();
}

public class Partner implements Serializable {
	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
	@JoinColumn(name="ID_FLAGS", nullable=false)
	private Flags flags;

	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
	@JoinColumn(name = "ID_PROCESS", nullable = false)
	private Process process;
}

and finally Flags entity:

public class Flags implements Serializable {
	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE,
mappedBy="flags")
	private Process process;

	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE,
mappedBy="flags")
	private Partner partner;
}

When I persist a Process with a Flags object and empty partners list
everything works as expected.

But when I try to persist a Process with a Flags object and non-empty
partners list (e.g., 1 Partner with its own Flags object) the
following thing happens:

in Apache Geronimo's console I see SQL dumps showing that both Flags
are being inserted, but one has all its fields set to NULL values:

16:26:51,765 TRACE [SQL] <t 4350647, conn 11983878> executing
prepstmnt 12428750 INSERT INTO FLAGS (a, b, c, d, e, f, g) VALUES (?,
?, ?, ?, ?, ?, ?) [params=(null) null, (null) null, (null) null,
(null) null, (null) null, (null
) null, (null) null]
16:26:51,765 TRACE [SQL] <t 4350647, conn 11983878> [0 ms] spent
16:26:51,765 TRACE [SQL] <t 4350647, conn 11983878> executing
prepstmnt 13678691 VALUES(IDENTITY_VAL_LOCAL())
16:26:51,781 TRACE [SQL] <t 4350647, conn 11983878> [0 ms] spent

Also, Flags' values linked to Partner object are copied into Flags
linked to Process object. (What a mess :( )

While debugging Apache Geronimo I saw that after
entityManager.persist, the reference to process.flags does not change,
but the Flags object now holds values of partner.flags instance
(values before invoking persist method), and partner.flags instance's
values are all set to null...

Maybe my mapping is wrong? Or am I missing something very obvious?

thanks,
Lukasz

Mime
View raw message