Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-dev] Question about EmbeddedAccessor#processEmbeddableClass()

Hi!

I've read through the eclipselink sources and like to add a few features.

Generally, I'd to say that it is a really well done and _very_ readable source! I did look at the sources for only 2 evenings now (and I really enjoyed digging into it), so don't be rude if I completely misinterpreted/not understood something yet :) 

There's a point in the EmbeddedAccesor which I do not understand:

In the function processEmbeddableClass(), a 'cached' EmbeddedAccessor instance is retrieved (line # 299)
        EmbeddableAccessor accessor = getProject().getEmbeddableAccessor(getReferenceClassName());

So I'll get the same EmbeddableAccessor instance for EVERY embedding of the same class.

A bit later in the source (line # 349), this EmbeddableAccessor will be filled with the OwningDescriptor:
            accessor.setOwningDescriptor(getOwningDescriptor());

BUT: imho the owning descriptor may be different for each @Embedded !?

In praxis this means, that the EmbeddableAccessor always points to the Table-Descriptor of the 'first' occurence (which one this ever may be -> random generator?), and the other ones may simply contain wrong values.

My example:

@Embeddable
public class Price {
	private BigDecimal amount;
	private String     currency;
}

@Entity
public class Purchase {
	@Id
	@GeneratedValue
	private int id;

	@Embedded(prefix = "N_")
	private Price netPrice;

	@Embedded(prefix = "G_")
	private Price grossPrice;
}

@Entity
public class OtherUseOfPrice {
	@Id
	@GeneratedValue
	private int id;

	@Embedded(prefix = "O_")
	private Price otherPrice;
}

In the debugger I got the following memory addresses:

O_	id=40	accessor=98	getowningDescriptor()=	45
N_ 	id=101	accessor=98	getowningDescriptor()=	102
G_	id=116	accessor=98	getowningDescriptor()=	102

And as expected, the accessor of the embeddings of netPrice (N_) and grossPrice (G_) point to the wrong m_owningDescriptor 45 instead of the correct 102

Does this have any impact on the result? If not, we also could remove the owningDescriptor from the EmbeddableAccessor, otherwise it may be a source of problems, isn't?






Back to the top