Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343632 - Can't map a compound constraint because of exception: The reference column name [y] mapped on the element [field x] does not correspond to a valid field on the mapping reference
Summary: Can't map a compound constraint because of exception: The reference column na...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---   Edit
Assignee: Guy Pelletier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-22 00:37 EDT by Xavier Callejas CLA
Modified: 2022-06-09 10:10 EDT (History)
6 users (show)

See Also:


Attachments
A WAR test case (Glassfish 3.1) (53.77 KB, application/zip)
2011-04-22 00:38 EDT, Xavier Callejas CLA
no flags Details
The ER diagram (30.45 KB, image/png)
2011-04-22 00:40 EDT, Xavier Callejas CLA
no flags Details
The DDL script of the DB test case (1.92 KB, text/x-sql)
2011-04-22 00:41 EDT, Xavier Callejas CLA
no flags Details
Proposed changes (33.83 KB, patch)
2011-07-06 15:52 EDT, Guy Pelletier CLA
guy.pelletier: iplog+
Details | Diff
Patch for 2.3.1 stream (34.22 KB, patch)
2011-07-11 09:53 EDT, Guy Pelletier CLA
guy.pelletier: iplog+
Details | Diff
Patch for 2.2.1 stream (35.20 KB, patch)
2011-07-12 11:58 EDT, Guy Pelletier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Xavier Callejas CLA 2011-04-22 00:37:17 EDT
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
Comment 1 Xavier Callejas CLA 2011-04-22 00:38:55 EDT
Created attachment 193898 [details]
A WAR test case (Glassfish 3.1)
Comment 2 Xavier Callejas CLA 2011-04-22 00:40:34 EDT
Created attachment 193899 [details]
The ER diagram
Comment 3 Xavier Callejas CLA 2011-04-22 00:41:14 EDT
Created attachment 193900 [details]
The DDL script of the DB test case
Comment 4 Xavier Callejas CLA 2011-04-22 00:45:38 EDT
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.
Comment 5 Xavier Callejas CLA 2011-04-22 01:03:40 EDT
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.
Comment 6 Guy Pelletier CLA 2011-04-26 10:48:39 EDT
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;
Comment 7 Xavier Callejas CLA 2011-04-26 18:14:18 EDT
Do you mean that instead of:

  private Clientes cliente;


I should try:

  private Integer cliente;


Or both:

  private Clientes cliente;
  private Integer idCliente;
Comment 8 Xavier Callejas CLA 2011-04-26 18:23:10 EDT
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?
Comment 9 Guy Pelletier CLA 2011-04-27 08:50:40 EDT
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.
Comment 10 Xavier Callejas CLA 2011-04-27 12:28:06 EDT
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.
Comment 11 Tom Ware CLA 2011-05-12 15:38:07 EDT
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.
Comment 12 Peter Krogh CLA 2011-06-20 13:53:25 EDT
Defferring for 2.3 bug scrub..
Comment 13 Guy Pelletier CLA 2011-07-06 15:52:35 EDT
Created attachment 199206 [details]
Proposed changes
Comment 14 Xavier Callejas CLA 2011-07-07 00:44:00 EDT
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 ?
Comment 15 Tom Ware CLA 2011-07-07 09:39:30 EDT
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.
Comment 16 Xavier Callejas CLA 2011-07-07 18:37:41 EDT
Downloading nightly build eclipselink-plugins-2.4.0.v20110707-r9689.zip , I will merge it in Glassfish v3.1 and will see :)
Comment 17 Guy Pelletier CLA 2011-07-11 09:53:52 EDT
Created attachment 199413 [details]
Patch for 2.3.1 stream
Comment 18 Guy Pelletier CLA 2011-07-11 09:57:40 EDT
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.
Comment 19 Guy Pelletier CLA 2011-07-12 11:58:32 EDT
Created attachment 199508 [details]
Patch for 2.2.1 stream

Backporting fix to 2.2.1 stream
Comment 20 Eclipse Webmaster CLA 2022-06-09 10:10:32 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink