This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 179644 - @JoinColumns definition is incomplete
Summary: @JoinColumns definition is incomplete
Status: RESOLVED WONTFIX
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 6.x
Hardware: All All
: P3 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-18 15:40 UTC by javydreamercsw
Modified: 2016-07-07 08:56 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
DB Schema (806.20 KB, text/plain)
2010-01-18 15:40 UTC, javydreamercsw
Details
SQL to recreate the database. (17.74 KB, application/octet-stream)
2010-01-18 15:42 UTC, javydreamercsw
Details

Note You need to log in before you can comment on or make changes to this bug.
Description javydreamercsw 2010-01-18 15:40:39 UTC
Created attachment 93391 [details]
DB Schema

6.8
jdk 1.6.18

I got the following error:

The @JoinColumns on the annotated element [field xincoWorkflow] from the entity class [class com.bluecubs.xinco.workflow.persistence.XincoWorkflowState] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn.

After further investigation the @JoinColumns definition in the class XincoWorkflowState that references XincoWorkflow was missing one of the components of XincoWorkflow composite key. Manually adding it did the trick.

The original definition was:

@JoinColumns({
        @JoinColumn(name = "xinco_workflow_id", referencedColumnName = "id", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "xinco_workflow_version", referencedColumnName = "version", nullable = false, insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private XincoWorkflow xincoWorkflow;

The modified definition:

@JoinColumns({
        @JoinColumn(name = "xinco_workflow_id", referencedColumnName = "id", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "user_link_id", referencedColumnName = "userLinkId", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "xinco_workflow_version", referencedColumnName = "version", nullable = false, insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private XincoWorkflow xincoWorkflow;

Notice the added userLinkId reference.

See attachments for sql and db schema for reproduction. This have been seen in dev. builds as well.
Comment 1 javydreamercsw 2010-01-18 15:42:09 UTC
Created attachment 93392 [details]
SQL to recreate the database.
Comment 2 javydreamercsw 2010-01-18 16:12:20 UTC
The correct modification is as follows:

@JoinColumns({
        @JoinColumn(name = "xinco_workflow_id", referencedColumnName = "id", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "xinco_workflow_id", referencedColumnName = "xincoWorkflowId", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "xinco_workflow_version", referencedColumnName = "version", nullable = false, insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private XincoWorkflow xincoWorkflow;
Comment 3 Sergey Petrov 2010-02-04 09:44:08 UTC
where is this error was produced? was it a message from eclipselink?

for me looks strange to have to references with the same name to different columns in one JoinColumns:

        @JoinColumn(name = "xinco_workflow_id", 
referencedColumnName = "id", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "xinco_workflow_id", 
referencedColumnName = "xincoWorkflowId", nullable = false, insertable = false, updatable = false)

also initial generation match table declaration with 
  CONSTRAINT `fk_xinco_state_xinco_workflow1`
    FOREIGN KEY (`xinco_workflow_id` , `xinco_workflow_version` )
    REFERENCES `xinco_workflow`.`xinco_workflow` (`id` , `version` )

Am I miss something? Why third @JoinColumn is required?
Comment 4 javydreamercsw 2010-02-04 17:32:45 UTC
The third column is due to a composite primary key. The generated class is missing half of the key (1 out of 2). If I'm correct one relationship is for another table and there's one to the entity itself.
Comment 5 Sergey Petrov 2010-04-07 14:10:55 UTC
Ok, I see the problem if try to deploy web project. 
Message from toplink is
javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
Exception Description: predeploy for PersistenceUnit [WebApplication4PU] failed.
Internal Exception: Exception [TOPLINK-7220] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The @JoinColumns on the annotated element [private e.XincoWorkflow e.XincoWorkflowState.xincoWorkflow] from the entity class [class e.XincoWorkflowState] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referenceColumnName elements must be specified in each such @JoinColumn.
        at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:643)

from EclipselInk:
Internal Exception: Exception [EclipseLink-7220] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The @JoinColumns on the annotated element [field xincoWorkflow] from the entity class [class e.XincoWorkflowState] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn.
        at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:210)
        ... 34 more
Caused by: Exception [EclipseLink-7220] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The @JoinColumns on the annotated element [field xincoWorkflow] from the entity class [class e.XincoWorkflowState] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn.
        at org.eclipse.persistence.exceptions.ValidationException.incompleteJoinColumnsSpecified(ValidationException.java:1808)
Comment 6 Sergey Petrov 2010-04-07 14:25:09 UTC
As sql maps only two from three columns in foreign key to primary key, this behaior seems to be expected and require some special handling, fas in general may not be supported by toplink/eclipselink etc and if will be supported may not be portable. Some workaround may be created, but may be it's hard to request such workarounds from nb or it should be some enhancment then.
see http://forums.oracle.com/forums/thread.jspa?threadID=448956 for example.
Your workaround seems to fix to pass validation rules but I don't see it match initial sql script.
Comment 7 Sergey Petrov 2010-04-09 14:08:17 UTC
> Enhancment
Current realization create 1-1 map from tables to entities, resulting relations may not fit in required support from providers, for example support for imcomplete maps is optional. It may be good to find a way to workaround such cases or to add warning from nb so user will get warning from nb instead of runtime problem.
Comment 8 javydreamercsw 2010-07-21 16:13:35 UTC
This issue is still present on 6.9.1
Comment 9 Martin Balin 2016-07-07 08:56:09 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss