gradle(spring boot): #id symbol not found - spring-boot

(Entity class)
enter image description here
(Error message)
enter image description here
dependencyenter image description here
dependencyAnother #Entity annotation is fine. but only #id annotation is not working...
(dependency)

Change from #id to #Id, case matters.

The error mesage is self-explaining. Java is case-sensitive programming language. id and Id are not the same here. You have to use #Id.

Related

Javax persistence id column and oracle generated always

It should be easy. Oracle has defined "generate always" for an id column. So there is no need to add this id to the insert statement. How do i define my entity that it is handling right.
#Entity
public class Example {
#Id
#GeneratedValue // if i remove this annotation than hibernate complains that i need to set it manually
#Column(name="ID", insertable=false, updatable=false)
private Long id;
}
in the error message i see that it still tries to add the id to the query.
My work-around for the column. Add the #id to an other column and remove the id column from entity definition :-D

Save only one field of an entity to another table

How do I only save a certain field/property of an Entity for another entity?
I have a Key entity with id and name properties.
In my Door entity, I would like to accept a Key but only save in the database the id
Is that possible?
Have a look at the #Transient annotation. Example from the docs:
#Entity
public class Employee {
#Id int id;
#Transient User currentUser;
...
}
#Transient will mark the annotated element to not be persisted.

Spring Boot and Kotlin - Cannot find my ID

I'm unable to get documents by Id (using Spring Boot and Mongo) - I've tried the following lines with no luck:
sRepository.findById(songId)
and
query.addCriteria(Criteria.where("_id").is(songId))
I've added the #Id annotation in my model to specify the id field:
#Document(collection = "songs")
data class Song(
#Id
val id: String,
and in my mongo the document I've added looks like:
{
"_id": "532132assad4a0",
"code": "956743458",
...
The Mongo repository class:
#Repository
interface SongRepository : MongoRepository<Song, String>
Any help would be appreciated - rather confused by it.
FOUND THE ANSWER:
I had to add the annotation #MongoId instead of #Id as I was saving it as a string, didn't want any other conversion happening on it.
Found at the documentation here: https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mapping.conventions.id-field

EL1007E: Property or field 'id' cannot be found on null

I'm trying to save my entity but this error occurs to me after changing the class ID from long to Long
I don't know why but hibernate doesn't save the object and thymeleaf sees that the ID field is null
Should I change it back to long ?
(Something strange)
I opened the debugger to see where the problem occurs
after calling EntityManager.persist() an ID is assigned to the object but it throws an exception saying that the object couldn't be saved
Thanks in advance
It means hibernate is not able to generate an id for the record.
Ensure that you are using #Id annotation and #GeneratedValue(strategy=GenerationType.AUTO) on id field and have proper getter/setters.
#Id
#GeneratedValue(strategy=GenerationType.AUTO)

Why spring create tow identical links for self and rel?

I cannot get why spring create the same links for self and rel? Is there a way how to disable it? I think that this only my issue because I didn't meet such problem in docs I read.
Here is my entity mapping:
#Getter
#Setter
#Document
public class Ad {
#Id
private String id;
private String description;
private Banner banner;
}
#Getter
#Setter
public class Banner {
private String id;
private String filename;
}
Here is my repository:
#RepositoryRestResource
public interface AdRepository extends CrudRepository<Ad, String> {
}
I touch the following url: http://localhost:8558/ads
I don't use any projections. My app is quite primitive now. There is nothing specific.
Thanks in advance!
My only guess is that maybe you're missing hashCode/equals and that's causing a problem
This is by design. The rel-based link allows you to see all contexts, while self link serves as the canonical link.
To further clarify, adjust your repository definition to extend not CrudRepository, but instead PagingAndSortingRepository. The two links rendered for each aggregate root will immediately look slightly different due to extended templating options.

Resources