Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 346413 - Incorrect validation for ID classes mapped as @EmbeddedId
Summary: Incorrect validation for ID classes mapped as @EmbeddedId
Status: RESOLVED INVALID
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: dali.general-inbox CLA
QA Contact:
URL: http://www.eclipse.org/forums/index.p...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-19 06:34 EDT by Karsten Wutzke CLA
Modified: 2011-05-19 11:57 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karsten Wutzke CLA 2011-05-19 06:34:08 EDT
Build Identifier: 20100617-1415

The following @EmbeddedId mappings result in incorrect validation:

[code]@Entity
@Table(name = "Groups")
@Name(value = "group")
public class Group implements Serializable
{
	@EmbeddedId
	private GroupId embeddedId;

	...
}
[/code]
[code]@Embeddable
public class GroupId implements Serializable
{
	@Column(name = "round_id")
	private Integer roundId;

	@Column(name = "ordinal_nbr")
	private Integer ordinalNbr = 1;

	...
}
[/code]

The Group class has two columns, both being PK columns. Dali shows an error

"Class GroupId is mapped, but is not included in any persistence unit"

The respective @IdClass mappings work in Dali without problems. Note, this error only occurrs with @EmbeddedId mappings.

The problem here seems to be the @Embeddable on the ID class. Removing it removes the Dali error. However, it's not correct to remove the @Embeddable. See here to confirm that the above mappings should be correct: http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Embedded_Id


Reproducible: Always

Steps to Reproduce:
1. Take any @EmbeddedId - ID class mappings (including @Embeddable)
2. Validate
3.
Comment 1 Paul Fullbright CLA 2011-05-19 09:26:39 EDT
The error you are seeing is because you are requiring that all mapped classes be listed in the persistence.xml (Persistent class management in project properties) yet GroupId is not listed.

You can either list GroupId in the persistence.xml or set persistent class management to "Discover annotated classes automatically" and this error should go away.

The reason this error does not apply for IdClass is because an ID class is not generally annotated, but instead is interpreted in the context of the entity that uses it.

If this does not match your situation, please feel free to reopen with more details.
Comment 2 Karsten Wutzke CLA 2011-05-19 10:04:25 EDT
I didn't know THAT. So, when using @IdClass mappings the ID class doesn't have to be listed and when using @EmbeddedId the ID class must be listed? This doesn't make sense to me honestly.

Where is the specification for this?
Comment 3 Karsten Wutzke CLA 2011-05-19 10:13:51 EDT
Wouldn't it be sufficient to display a warning instead of an error here? Is this configurable?
Comment 4 Karsten Wutzke CLA 2011-05-19 10:23:54 EDT
Where is the "Discover annotated classes automatically" option for my existing web project?

Note by "configurable" in meant a setting in the form error, warning, or ignore for these classes.
Comment 5 Karsten Wutzke CLA 2011-05-19 10:33:05 EDT
Sorry, found "Discover annotated classes automatically" under Project -> Properties -> Java Persistence
Comment 6 Neil Hauge CLA 2011-05-19 10:33:45 EDT
(In reply to comment #2)
> I didn't know THAT. So, when using @IdClass mappings the ID class doesn't have
> to be listed and when using @EmbeddedId the ID class must be listed? This
> doesn't make sense to me honestly.
> 
> Where is the specification for this?

From the JPA 2.0 spec:

8.2.1.6 mapping-file, jar-file, class, exclude-unlisted-classes
The following classes must be implicitly or explicitly denoted as managed
persistence classes to be included within a persistence unit: entity classes;
embeddable classes; mapped superclasses.

That said, as Paul mentioned, whether this listing is required is up to the
user (based on their config), and this can be set in the project properties on
the JPA node or during project creation.  Explicitly listing classes is not
required in most configurations, but is the default as it guarantees that your
classes will be managed at runtime.

(In reply to comment #3)
> Wouldn't it be sufficient to display a warning instead of an error here? Is
> this configurable?

Yes, this is configurable at the workspace or project level.  See the Java
Persistence->JPA/JPA -> Error/Warnings->Persistence Unit settings.
Comment 7 Paul Fullbright CLA 2011-05-19 11:57:19 EDT
(In reply to comment #3)
> Wouldn't it be sufficient to display a warning instead of an error here? Is
> this configurable?

It's debatable.  In general we've tried to make things errors that will fail at runtime, and warnings if it's "generally not a good idea".  At least in the reference implementation, this scenario will fail at runtime.