Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Help with error: number of referencing and referenced column
Help with error: number of referencing and referenced column [message #389400] Wed, 03 June 2009 05:16 Go to next message
Gabriella Turek is currently offline Gabriella TurekFriend
Messages: 1
Registered: July 2009
Junior Member
I have 3 objects which I will list here with only the relevant code with
annotations:

OBJECT #1 : column ID index
uniqueness constraint on the column pair (NAME, ORGANISATION)
one to many relationship with object #2

@Entity
@Table(name = "module", uniqueConstraints = @UniqueConstraint(columnNames
= { "NAME", "ORGANISATION" }))
public class Module implements Serializable
{
private static final long serialVersionUID = 8618562883278938873L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="ID")
private Long moduleId;

@Column(name = "NAME")
private String name;

@Column(name = "ORGANISATION")
private String organisation;

@OneToMany(mappedBy = "module", cascade = CascadeType.ALL)
private List<ModuleVersion> versions = new ArrayList<ModuleVersion>();

etc, etc ....
}

OBJECT #2 column VERSION_ID index
foreign key MODULE_ID mapped to ID in OBJECT #1
uniqueness constraint on the column pair (MODULE_ID, VERSION)
many to one relationship with object #1
one to many relationship with object #3

@Entity
@Table(name = "moduleversion", uniqueConstraints =
@UniqueConstraint(columnNames = { "MODULE_ID", "VERSION" }))
public class ModuleVersion implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "VERSION_ID")
private Long versionId;

@Column(name = "VERSION")
private String version;

@ManyToOne
@PrimaryKeyJoinColumn(name = "MODULE_ID", referencedColumnName = "ID")
private Module module;

@OneToMany(mappedBy = "moduleVersion", cascade = CascadeType.ALL)
private List<DownloadRecord> downloads = new ArrayList<DownloadRecord>();

etc, etc
}

OBJECT #3 index column DOWNLOAD_ID
foreign key DOWNLOAD_VERSION_ID mapped to VERSION_ID in OBJECT #2
uniqueness constraint on the column pair (MODULE_ID, VERSION)
many to one relationship with object #2


@Entity
@Table(name = "downloadrecord")
public class DownloadRecord implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "DOWNLOAD_ID")
private Long downloadId;

@ManyToOne
@PrimaryKeyJoinColumn(name = "DOWNLOADED_VERSION_ID", referencedColumnName
= "VERSION_ID")
private ModuleVersion moduleVersion;

etc, etc

}

Finally the error output:

14:15:40,890 INFO [SchemaUpdate] updating schema
14:15:40,937 INFO [TableMetadata] table found: public.downloadrecord
14:15:40,937 INFO [TableMetadata] columns: [downloaddate, downloadedby,
moduleversion_version_id, download_id]
14:15:40,937 INFO [TableMetadata] foreign keys: []
14:15:40,937 INFO [TableMetadata] indexes: [downloadrecord_pkey]
14:15:40,984 INFO [TableMetadata] table found: public.module
14:15:40,984 INFO [TableMetadata] columns: [id, moduletype, description,
isdeleted, organisation, name, deletiondate, deletedby]
14:15:40,984 INFO [TableMetadata] foreign keys: []
14:15:40,984 INFO [TableMetadata] indexes: [module_pkey]
14:15:41,015 INFO [TableMetadata] table found: public.moduleversion
14:15:41,015 INFO [TableMetadata] columns: [author, modulevisibility,
submissiondate, submittedby, module_id, md5, version_id, uri,
creationdate, rsversion, version]
14:15:41,015 INFO [TableMetadata] foreign keys: [fk5061a4ec79e9af3,
fk_moduleversion_module_id]
14:15:41,015 INFO [TableMetadata] indexes: [moduleversion_pkey]
14:15:41,015 ERROR [SchemaUpdate] Unsuccessful: alter table downloadrecord
add constraint FK5A7AAED963EF8508 foreign key (moduleVersion_VERSION_ID)
references moduleversion
14:15:41,015 ERROR [SchemaUpdate] ERROR: number of referencing and
referenced columns for foreign key disagree
14:15:41,015 INFO [SchemaUpdate] schema update complete

I know the why of this error (see http://archives.postgresql.org/pgsql-sq
... g00349.php), but I can't figure out how to resolve it in code. Any
ideas?
Thanx
Gaby
Re: Help with error: number of referencing and referenced column [message #389412 is a reply to message #389400] Mon, 08 June 2009 19:43 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Could you include the full error/stack. Is this error from DDL that
EclipseLink generated, or from you own script?

In you mappings the PrimaryKeyJoinColumn in Downloaded should just be a
regular JoinColumn, unless you also have a Basic for the same column.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Previous Topic:ReadObjectQuery Problem
Next Topic:Expressions query generated property but execution returns no results when they
Goto Forum:
  


Current Time: Thu Apr 25 22:38:20 GMT 2024

Powered by FUDForum. Page generated in 0.02663 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top