Cannot query a table with composite key in Hibernate
Автор: Emrah KAYA
Загружено: 2024-10-12
Просмотров: 0
Описание:
Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: / ky.emrah
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Cannot query a table with composite key in Hibernate
I have a table with userId and listingId. They together form a composite key.
The key itself:
@Data
@Embeddable
public class FavoriteListingId implements Serializable {
@Column(name = "user_id", columnDefinition = "CHAR(36)")
private String userId;
@Column(name = "listing_id", columnDefinition = "CHAR(11)")
private String listingId;
}
@Data
@Embeddable
public class FavoriteListingId implements Serializable {
@Column(name = "user_id", columnDefinition = "CHAR(36)")
private String userId;
@Column(name = "listing_id", columnDefinition = "CHAR(11)")
private String listingId;
}
The table:
@Getter
@Setter
@Entity
@Table(name = "favorite_listing")
public class FavoriteListingEntity {
@EmbeddedId
FavoriteListingId id;
}
@Getter
@Setter
@Entity
@Table(name = "favorite_listing")
public class FavoriteListingEntity {
@EmbeddedId
FavoriteListingId id;
}
The repository:
@Repository
public interface FavoriteListingRepository extends JpaRepository FavoriteListingEntity, FavoriteListingId {
int countByListingId(String listingId);
List FavoriteListingEntity findAllByUserId(String userId);
}
@Repository
public interface FavoriteListingRepository extends JpaRepository FavoriteListingEntity, FavoriteListingId {
int countByListingId(String listingId);
List FavoriteListingEntity findAllByUserId(String userId);
}
But findAllByUserId does not work. It gives me the following error:
No property userId found for type FavoriteListingEntity!
No property userId found for type FavoriteListingEntity!
What am I doing wrong here?
Tags: java,spring-boot,hibernate,jpaSource of the question:
https://stackoverflow.com/questions/7...
Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: