javaspringeclipselink

Exception for using primitive type as id with SPRING and Eclipselink


I am moving my project to SPRING using Eclipselink as JPA provider. After declaring the @Repository and @Service classes and run the application I get an exception that seems to forbid the use of primitive types ad entity IDS:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'flotaService': Unsatisfied dependency expressed through field 'repository': Error creating bean with name 'flotaRepository' defined in zerog.flota.FlotaRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Expected id attribute type [class java.lang.Long] in the existing id attributes [[SingularAttributeImpl[BasicTypeImpl@1605430451:long [ javaType: long],org.eclipse.persistence.mappings.DirectToFieldMapping[id-->flotas.id]]]] on the identifiable type [EntityTypeImpl@1516081143:Flota [ javaType: class zerog.flota.Flota descriptor: RelationalDescriptor(zerog.flota.Flota --> [DatabaseTable(flotas)]), mappings: 58]] but found attribute types [[long]].

My classes:

public class Flota{
    
@Id
@TableGenerator(name="TABLE_GEN_FLOTA", table="sequence", pkColumnName="SEQ_NAME", valueColumnName="SEQ_COUNT", pkColumnValue="flotas")
@GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN_FLOTA")
@Column(name = "id")
protected long id;

// code...
}

@Repository
public interface FlotaRepository extends JpaRepository<Flota, Long> 
{

@Service
public class FlotaService {

    @Autowired
    private FlotaRepository repository;

    public List<Flota> findAll() {
        return repository.findAll();
    }

    public Optional<Flota> findById(long id) {
        return repository.findById(id);
    }

}

If I change id data type to Long it works. The thing is that I have searched many Spring examples that use long as ids, but I havent been able to find any information related to this. Is there any SPRING configuration I need to set?

Thansk in advance


Solution

  • I have not been able to find any other information regarding to the possibility of using primitive types as ID. When you use JpaRepository to are forced to use an object.