Community
Participate
Working Groups
Build Identifier: 2.2.0 This is a problem of Eclipselink since 2.1.x that stop me from upgrade my applications to Glasfish 3.1. I hopped this would be fixed in final 3.1 but isn't. I have attached a test case with 3 database tables: Clientes, Operaciones, RoutingOrders; attached is a ER diagram. RoutingOrders table has a foreign constraint compounded of 2 fields: [Cliente, Operacion ] from for foreign table Operaciones; attached is the DDL. Please look at these entities code: @Entity @Table(name = "Operaciones") @XmlRootElement @NamedQueries({ @NamedQuery(name = "Operaciones.findAll", query = "SELECT o FROM Operaciones o")}) public class Operaciones implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @NotNull @Column(name = "idOperacion") private Integer idOperacion; @OneToOne(cascade = CascadeType.ALL, mappedBy = "operaciones") private RoutingOrders routingOrders; @JoinColumn(name = "Cliente", referencedColumnName = "idCliente") @ManyToOne(optional = false) private Clientes cliente; ... } @Entity @Table(name = "RoutingOrders", uniqueConstraints = @UniqueConstraint(columnNames = {"Cliente", "Operacion"})) @XmlRootElement @NamedQueries({ @NamedQuery(name = "RoutingOrders.findAll", query = "SELECT r FROM RoutingOrders r")}) @AttributeOverride(name = "Cliente", column = @Column(name = "Cliente")) public class RoutingOrders implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @NotNull @Column(name = "idRoutingOrder") private Integer idRoutingOrder; @JoinColumns({ @JoinColumn(name = "Cliente", referencedColumnName = "Cliente"), @JoinColumn(name = "Operacion", referencedColumnName = "idOperacion")}) @OneToOne(optional = false, targetEntity=Operaciones.class) private Operaciones operaciones; ... } The problem seems to be in the 'operaciones' field, in the ... referencedColumnName = "Cliente" ..., when I try to deploy the application into Glassfish 3.1 it throws the following exception: Internal Exception: Exception [EclipseLink-7333] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.ValidationException Exception Description: The reference column name [Cliente] mapped on the element [field operaciones] does not correspond to a valid field on the mapping reference... I have search for days looking for the solution but I gave up, there is the uppercase association thing but this doesn't help. Reproducible: Always
Created attachment 193898 [details] A WAR test case (Glassfish 3.1)
Created attachment 193899 [details] The ER diagram
Created attachment 193900 [details] The DDL script of the DB test case
operaciones field in RoutingOrder entity should tie Cliente table field, right? I mean if, for example, I set the operaciones field of a RoutingOrder instance the Cliente table field should be set atomatically (when commit), at least this work like this in Eclipselink 2.0.1.
I am using Glassfish 3.0.1 + Eclipselink 2.1.2 and this test case works on it, this stop working in Eclipselink 2.2.0, this is why I cannot use Glassfish 3.1, I have tried to downgrade Eclipse in Glassfish 3.1 but I haven't been able.
Humm, it's trying and failing on the look up to the referenced column name (assuming it is a basic field/mapping) on Operaciones. Try adding a read only mapping to Cliente, that is, @Basic @Column(name="Cliente", insertable="false", updatable="false") private Integer cliente;
Do you mean that instead of: private Clientes cliente; I should try: private Integer cliente; Or both: private Clientes cliente; private Integer idCliente;
It works! if I add a @Basic field it works. @Entity @Table(name = "Operaciones") @XmlRootElement @NamedQueries({ @NamedQuery(name = "Operaciones.findAll", query = "SELECT o FROM Operaciones o")}) public class Operaciones implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @NotNull @Column(name = "idOperacion") private Integer idOperacion; @OneToOne(cascade = CascadeType.ALL, mappedBy = "operaciones") private RoutingOrders routingOrders; @JoinColumn(name = "Cliente", referencedColumnName = "idCliente") @ManyToOne(optional = false) private Clientes cliente; @Basic @Column(name="Cliente", insertable = false, updatable = false) private Integer idCliente; ... } Why I need to do this? is this still a bug?
It's more of an enhancement really. Section 10.1.21 of the JPA spec states: "Support for referenced columns that are not primary key columns of the referenced table is optional. Applications that use such mappings will not be portable." EclipseLink does go beyond this statement and allows you to map to non primary key basic mappings. And the only reason it worked previously is because EclipeLink didn't validate the field (it just used what was specified in the join column). This is incorrect though because the referenced field must be looked up to ensure column length, precision etc are respected. EclipseLink can support your case so this bug is still valid.
Glassfish/Netbeans JPA Entity Classes from Database Wizard generate the classes without knowing this new validation so it does not generate a extra primitive type for the foreign constraint field that is not PK. Because, as you said, previously it was not validated my application could be deployed without problems, but now I can't upgrade to Eclipselink 2.2. I have a lot of entities classes in my real enterprise application, I don't want to modify one by one. May I expect a fix for Eclipselink to use the non primitive type foreign field? Thank you.
Setting target and priority. See the following page for the meanings of these fields: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines Community: Please vote for this bug if it is important to you. Votes are one of the main criteria we use to determine which bugs to fix next.
Defferring for 2.3 bug scrub..
Created attachment 199206 [details] Proposed changes
Thanks Guy! How can I test your proposed changes? Can I merge them into current 2.3 source code for testing in Glassfish v3.1 ?
Updating target to 2.3.1. We will put this fix into 2.3.1. In the meantime, you can use our trunk nightly builds to test - The 2.3 release was recent enough so the streams have not diverged much.
Downloading nightly build eclipselink-plugins-2.4.0.v20110707-r9689.zip , I will merge it in Glassfish v3.1 and will see :)
Created attachment 199413 [details] Patch for 2.3.1 stream
Changes submitted to trunk and 2.3.1 stream. Verified by: Chris Delahunt Tests: Model added exposing error during metadata processing. With fix in place, error does not occur.
Created attachment 199508 [details] Patch for 2.2.1 stream Backporting fix to 2.2.1 stream
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink