Skip to content

The IDE compiler have a lot of wrong problem report, maven build is okay #1159

Closed

Description

@yiukalun

The IDE compiler wrongly reporting problem for several scenario.

  1. Complaining about JpaRepository using composite key. When using composite key in JPA class, extending JpaRepository interface will report error "Expected Domain ID type is 'java.lang.Long", but it only complaining on some class, some other class using same composite key will have no problem.

  2. I'm using org.json.JSONObject, the IDE already reference to the spring-starter org.json package and keep complaining that the toMap() function is not available from class.

Activity

  1. martinlippert commented on Dec 13, 2023

    @martinlippert
    Member

    Can you attach a sample project that reproduces these wrong problem reporting? That would be awesome.

    With regards to 1., this clearly sounds like an issue with the Spring specific validation that we should fix.
    With regards to 2., this sounds like a project setup or dependency resolution issue, the sample project would be interesting to analyze here.

    Which IDE are you using? The Eclipse based Spring Tools or working inside of VSCode?

  2. BoykoAlex commented on Dec 13, 2023

    @BoykoAlex
    Contributor

    @yiukalun any chance you can paste here a code snippet for something that has a problem marker that reads: Expected Domain ID type is 'java.lang.Long'?

  3. yiukalun commented on Dec 14, 2023

    @yiukalun
    Author

    compositeKey
    compositeKey1

  4. BoykoAlex commented on Dec 14, 2023

    @BoykoAlex
    Contributor

    @yiukalun I have pushed what i think would the fix for the composite repo key: de4a132
    Please try to update your sts from a nightly update site starting from ~2 hours from now. See https://cdn.spring.io/spring-tools/snapshot/STS4/nightly-distributions.html for snapshot distros and update sites

  5. added this to the 4.21.1.RELEASE milestone on Dec 15, 2023
  6. martinlippert commented on Dec 15, 2023

    @martinlippert
    Member

    2. I'm using org.json.JSONObject, the IDE already reference to the spring-starter org.json package and keep complaining that the toMap() function is not available from class.

    @yiukalun If you still face this issue and if you can create a small sample project for this, please create a separate issue for this and attach the sample project. Happy to look into this.

  7. BoykoAlex commented on Dec 19, 2023

    @BoykoAlex
    Contributor

    @yiukalun should be fixed. Please re-open if you still see issues around composite key. (The fix is de4a132

  8. raneem13j commented on Dec 21, 2023

    @raneem13j

    I have the same problem, I am using VS code, and in another repo it works

    `package com.Dazzle.app.Dazzle.repositories;

    import java.util.Optional;

    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.stereotype.Repository;

    import com.Dazzle.app.Dazzle.models.user.ERole;
    import com.Dazzle.app.Dazzle.models.user.Role;

    @repository
    public interface RoleRepository extends JpaRepository<Role, Long> {
    Optional findByName(ERole name);
    }
    `

    `package com.Dazzle.app.Dazzle.models.user;

    import jakarta.persistence.*;

    @entity
    @table(name = "roles")
    public class Role {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    
    @Enumerated(EnumType.STRING)
    @Column(length = 20)
    private ERole name;
    
    
    public Role() {
    
    }
    
    public Role(ERole name) {
      this.name = name;
    }
    
    public Integer getId() {
        return id;
    }
    
    public void setId(Integer id) {
        this.id = id;
    }
    
    public ERole getName() {
        return name;
    }
    
    public void setName(ERole name) {
        this.name = name;
    }
    

    }
    `

  9. BoykoAlex commented on Dec 22, 2023

    @BoykoAlex
    Contributor

    @raneem13j I'm not an expert in Spring Data :-\ I've trimmed your use case to the one below which I hope is showing the same issue:

    			package demo;
    			
    			
    			import org.springframework.data.jpa.repository.JpaRepository;
    			import org.springframework.stereotype.Repository;
    			
    			@Repository
    			public interface RoleRepository extends JpaRepository<Role, Long> {
    				
    			}

    and the domain class:

    			package demo;
    			
    			import javax.persistence.Entity;
    			import javax.persistence.Id;
    			import javax.persistence.Table;
    			
    			@Entity
    			@Table(name = "roles")
    			public class Role {
    			
    				@Id
    				private Integer id;
    			
    				public Integer getId() {
    					return id;
    				}
    			
    				public void setId(Integer id) {
    					this.id = id;
    				}
    			
    			}

    It might be right in forcing to switch the repo key to Inetger to match the domain class id but as I mentioned earlier I'm far from spring data expert. Thus, I left them a question asking whether the marker is correct in this case. If it is not correct I'm curious what would be the rule for this case... both classes have corresponding primitive types if one primitive type can be cast to another perhaps is the rule (?)

  10. BoykoAlex commented on Dec 22, 2023

    @BoykoAlex
    Contributor

    @raneem13j Fixed with 1665b3f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions