spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
924 stars 562 forks source link

@MappedSuperclass [DATAREST-28] #411

Open spring-projects-issues opened 12 years ago

spring-projects-issues commented 12 years ago

wims.tijd opened DATAREST-28 and commented

entity extending Abstract base class : org.springframework.data.jpa.domain.AbstractPersistable

resolved by :

org.springframework.data.rest.webmvc.RepositoryRestController.entity org.springframework.data.rest.webmvc.RepositoryRestController.linkedEntity

results in :

Provided id of the wrong type for class repository.domain.ColumnMetaData. Expected: class java.lang.Long, got class java.lang.String; nested exception is java.lang.IllegalArgumentException: Provided id of the wrong type for class repository.domain.ColumnMetaData. Expected: class java.lang.Long, got class java.lang.String


Affects: 1.0.0.RC1

Issue Links:

spring-projects-issues commented 12 years ago

Jon Brisbin commented

Can you provide a little more information about how this domain model is structured? Are both parent and child entities descending from AbstractPersistable? Or is just one or the other? How is the relationship defined in the parent? That information would help a lot so I could try and reproduce the problem. As it is, I don't have enough information to do that

spring-projects-issues commented 12 years ago

wims.tijd commented

it is not the relationship,

removing the AbstractPersistable and declaring an @Id in the entity works, using AbstractPersistable the type of @Id in this @MappedSuperclass is incorrectly resolved

spring-projects-issues commented 12 years ago

Jon Brisbin commented

Are you using Hibernate version 4.1.5 or later? Earlier versions of Hibernate didn't correctly return meta information for superclasses.

https://hibernate.onjira.com/browse/HHH-6896

spring-projects-issues commented 12 years ago

wims.tijd commented

switched to hibernate 4.1.6.Final and data-rest 1.0.0.RC2 : org.hibernate.TypeMismatchException: Provided id of the wrong type for class . Expected: class java.lang.Long, got class java.lang.String org.springframework.data.jpa.repository.support.SimpleJpaRepository.findOne org.springframework.data.rest.webmvc.RepositoryRestController.entity

spring-projects-issues commented 12 years ago

wims.tijd commented

entity TableMetaData extends AbstractPersistable entity ColumnMetaData does define it's own @Id

@Test public void metaInfo(){ Metamodel metamodel = entityManager.getMetamodel(); EntityType<?> entityType = metamodel.entity(TableMetaData.class); logger.info("{}",entityType);

    logger.info("{}",entityType.getIdType().getJavaType());

    JpaAttributeMetadata idAttribute = new JpaAttributeMetadata(entityType, entityType.getId(entityType.getIdType().getJavaType()));
    logger.info("{}",idAttribute);

    entityType = metamodel.entity(ColumnMetaData.class);
    logger.info("{}",entityType);

    logger.info("{}",entityType.getIdType().getJavaType());

    idAttribute = new JpaAttributeMetadata(entityType, entityType.getId(entityType.getIdType().getJavaType()));
    logger.info("{}",idAttribute);

}

result :

MetaDataImportTest - org.hibernate.ejb.metamodel.EntityTypeImpl@1410a85 MetaDataImportTest - interface java.io.Serializable MetaDataImportTest - JpaAttributeMetadata{name='id', attribute=org.hibernate.ejb.metamodel.SingularAttributeImpl$Identifier@126aaca, type=interface java.io.Serializable, field=private java.io.Serializable org.springframework.data.jpa.domain.AbstractPersistable.id, getter=public java.io.Serializable org.springframework.data.jpa.domain.AbstractPersistable.getId(), setter=null}

MetaDataImportTest - org.hibernate.ejb.metamodel.EntityTypeImpl@c80e21 MetaDataImportTest - class java.lang.Long MetaDataImportTest - JpaAttributeMetadata{name='id', attribute=org.hibernate.ejb.metamodel.SingularAttributeImpl$Identifier@6e3fe4, type=class java.lang.Long, field=private java.lang.Long be.mil.cccis.esb.repository.domain.ColumnMetaData.id, getter=null, setter=null}

so it seems hibernate related