Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yiukalun opened this issue Dec 13, 2023 · 9 comments
Closed

Comments

@yiukalun
Copy link

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.

@martinlippert
Copy link
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?

@BoykoAlex
Copy link
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'?

@yiukalun
Copy link
Author

compositeKey
compositeKey1

@BoykoAlex
Copy link
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

@martinlippert
Copy link
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.

@BoykoAlex
Copy link
Contributor

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

@raneem13j
Copy link

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;
}

}
`

@BoykoAlex
Copy link
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 (?)

@BoykoAlex
Copy link
Contributor

@raneem13j Fixed with 1665b3f

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

No branches or pull requests

4 participants