Bug 415027 - Metamodel lookup for primitive id fails
Summary: Metamodel lookup for primitive id fails
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X
: P2 normal with 9 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-14 04:15 EDT by Oliver Drotbohm CLA
Modified: 2022-06-09 10:20 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Drotbohm CLA 2013-08-14 04:15:16 EDT
Suppose we have a class

@Entity
class SampleWithPrimitiveId {

  @Id long id;
}

Trying to lookup the id property through

IdentifiableType type = // …
type.getId(type.getIdType().getJavaType())

fails with

Expected id attribute type [class java.lang.Long] on the existing id attribute [SingularAttributeImpl[BasicTypeImpl@1973147899:long [ javaType: long],org.eclipse.persistence.mappings.DirectToFieldMapping[id-->SAMPLEWITHPRIMITIVEID.ID]]] on the identifiable type [EntityTypeImpl@1313610571:SampleWithPrimitiveId [ javaType: class org.springframework.data.jpa.domain.sample.SampleWithPrimitiveId descriptor: RelationalDescriptor(org.springframework.data.jpa.domain.sample.SampleWithPrimitiveId --> [DatabaseTable(SAMPLEWITHPRIMITIVEID)]), mappings: 1]] but found attribute type [long].

I'll prepare a reproducing branch in Spring Data JPA. I can currently only test that against 2.4.0 as both 2.4.2 and 2.5.0 fail to bootstrap due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=411560.
Comment 1 Oliver Drotbohm CLA 2013-08-14 04:22:21 EDT
Steps to reproduce:

git clone https://github.com/SpringSource/spring-data-jpa
cd spring-data-jpa
git checkout eclipselink-415027
mvn clean test

The EclipseLink version is held in a property in the pom.xml so it should be easy to test that running against more recent versions as well.
Comment 2 Tom Ware CLA 2013-08-19 10:14:02 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 3 Gilberto Caetano de Andrade CLA 2014-08-11 15:23:56 EDT
Having the same problem when using MapsId:
[CODE]
@Entity
@Table(name = "etl_servidor_publico", schema = "sapeo")
public class EtlServidorPublico implements Serializable {

    @Id
    @Column(name = "nomeacao_id")
    private Long id;
    @MapsId
    @OneToOne(optional = false)
    @JoinColumn(name = "nomeacao_id", nullable = false, updatable = false)
    private Nomeacao nomeacao;
[/CODE]

The exception:
[CODE]
java.lang.IllegalArgumentException: Expected id attribute type [class java.lang.Long] on the existing id attribute [SingularAttributeImpl[EntityTypeImpl@535754249:Nomeacao [ javaType: class br.gov.to.secad.sapeo.model.Nomeacao descriptor: RelationalDescriptor(br.gov.to.secad.sapeo.model.Nomeacao --> [DatabaseTable(sapeo.nomeacao)]), mappings: 12],org.eclipse.persistence.mappings.OneToOneMapping[nomeacao]]] on the identifiable type [EntityTypeImpl@22731072:EtlServidorPublico [ javaType: class br.gov.to.secad.sapeo.model.EtlServidorPublico descriptor: RelationalDescriptor(br.gov.to.secad.sapeo.model.EtlServidorPublico --> [DatabaseTable(sapeo.etl_servidor_publico)]), mappings: 19]] but found attribute type [class br.gov.to.secad.sapeo.model.Nomeacao].
[/CODE] 

Tested against 2.4.0, 2.4.2 and 2.5.0.
Comment 4 Mauro Molinari CLA 2014-12-02 09:52:01 EST
I have the same problem with EclipseLink 2.5.2.
Comment 5 Kai Zimmermann CLA 2015-09-22 04:03:23 EDT
Also in 2.6.0
Comment 6 Uwe Pachler CLA 2019-01-01 04:51:56 EST
Same Problem in 2.7.1.

Occurred for me when I changed the @Id type of an entity from java.lang.Long to long. There's nothing special about the entity, however, it is part of a @OneToMany/@ManyToOne relation (the entity where it occurs holds the owning @ManyToOne side).

Does anyone know why this is happening? Workarounds?
Comment 7 Eclipse Webmaster CLA 2022-06-09 10:20:29 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink