他 return null,来自我的存储库,具有 UUID,主 ID
He return null, from my repository with UUID, primary id
我有一个这样的实体,带有 uuid pk 密钥...
package com.bonrefil_rest_api.bonrefil_rest_api.data.entity;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import javax.persistence.*;
import java.util.*;
@Entity
@Table(name = "annonce")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Annonce {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@Column(length = 16, name = "annonce_id", nullable = false, updatable = false)
private UUID annonce_id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String title;
@Column(nullable = false)
private String description;
@Column(nullable = false)
private double price;
@Column(nullable = false)
private int quantity;
@Column(nullable = false)
private String salesTerms;
@JoinColumn(name = "author_client_id")
private UUID author;
@OneToOne(mappedBy = "annonce", optional = false)
private AnnoncePicture picture;
@ManyToMany
@JoinTable(name = "annonce_carts",
joinColumns = @JoinColumn(name = "annonce_id"),
inverseJoinColumns = @JoinColumn(name = "cart_id"))
private List<Cart> cartList = new ArrayList<>();
@OneToMany(mappedBy = "conversationOnAnnonce")
private Collection<Conversation> conversationList = new ArrayList<>();
@ManyToMany(mappedBy = "annonceList")
private List<Categorie> categorieList = new ArrayList<>();
@Enumerated
@ElementCollection(fetch = FetchType.LAZY)
private List<State> states;
@OneToMany(mappedBy = "noteFor")
private Collection<Note> noteList;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "createdAt", insertable = false, columnDefinition = "DATETIME DEFAULT NOW()")
private Date createdAt;
@Column(name = "updateAt", nullable = true, columnDefinition = "DATETIME")
private Date updateAt;
@Column(nullable = false)
private String categorie;
}
我有一个这样的存储库
@RepositoryRestResource
public interface AnnonceRepository extends JpaRepository<Annonce, UUID> {
List<Annonce> getAllByCategorie(String categorie);
List<Annonce> findAnnonceByAuthor(Client author);
}
一个控制器用于检索一个 uuid 像这样的 annonce
@GetMapping("/{annonce_id}")
public ResponseEntity<Optional<AnnonceDTO>> getOne(@PathVariable UUID annonce_id){
return ResponseEntity.ok(annonceService.getOne(annonce_id));
}
以及
的服务
@Override
public Optional<AnnonceDTO> getOne(UUID annonceId) {
if (!annonceRepository.existsById(annonceId))
throw new ElementNotFoundException();
return annonceRepository.findById(annonceId).map(annonceMapper::toDTO);
}
我试试邮递员
http://localhost:8080/annonce/0e7b4f11-b7eb-4c83-83e3-d08955ddd7ae
但是 return 为空,并且该行在我的 mysql 数据库中...
我没有错误,只是为空,我一直在寻找原因,但我没有找到,但还有一些事情要知道?...使用 UUID?...我已经看到了在我的数据库上,该行是 blob,我在数据库上尝试 select,这只适用于 unhex,但是在 spring 上,UUID 是 fonctionnaly inside ?..
有人可以帮助我,
非常感谢?..
这里也是mysql
我找到了在存储库上查询的解决方案....
@Query("SELECT CASE WHEN COUNT(a) > 0 THEN true ELSE false END FROM Annonce a WHERE a.annonce_id = :annonceId")
Boolean ifExistByUuid(@Param("annonceId") UUID annonce_id);
@Query("SELECT a FROM Annonce a WHERE a.annonce_id= ?1")
Annonce findOneByUuid(UUID annonce_id);
非常感谢您的帮助....工作正常....
我有一个这样的实体,带有 uuid pk 密钥...
package com.bonrefil_rest_api.bonrefil_rest_api.data.entity;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import javax.persistence.*;
import java.util.*;
@Entity
@Table(name = "annonce")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Annonce {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@Column(length = 16, name = "annonce_id", nullable = false, updatable = false)
private UUID annonce_id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String title;
@Column(nullable = false)
private String description;
@Column(nullable = false)
private double price;
@Column(nullable = false)
private int quantity;
@Column(nullable = false)
private String salesTerms;
@JoinColumn(name = "author_client_id")
private UUID author;
@OneToOne(mappedBy = "annonce", optional = false)
private AnnoncePicture picture;
@ManyToMany
@JoinTable(name = "annonce_carts",
joinColumns = @JoinColumn(name = "annonce_id"),
inverseJoinColumns = @JoinColumn(name = "cart_id"))
private List<Cart> cartList = new ArrayList<>();
@OneToMany(mappedBy = "conversationOnAnnonce")
private Collection<Conversation> conversationList = new ArrayList<>();
@ManyToMany(mappedBy = "annonceList")
private List<Categorie> categorieList = new ArrayList<>();
@Enumerated
@ElementCollection(fetch = FetchType.LAZY)
private List<State> states;
@OneToMany(mappedBy = "noteFor")
private Collection<Note> noteList;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "createdAt", insertable = false, columnDefinition = "DATETIME DEFAULT NOW()")
private Date createdAt;
@Column(name = "updateAt", nullable = true, columnDefinition = "DATETIME")
private Date updateAt;
@Column(nullable = false)
private String categorie;
}
我有一个这样的存储库
@RepositoryRestResource
public interface AnnonceRepository extends JpaRepository<Annonce, UUID> {
List<Annonce> getAllByCategorie(String categorie);
List<Annonce> findAnnonceByAuthor(Client author);
}
一个控制器用于检索一个 uuid 像这样的 annonce
@GetMapping("/{annonce_id}")
public ResponseEntity<Optional<AnnonceDTO>> getOne(@PathVariable UUID annonce_id){
return ResponseEntity.ok(annonceService.getOne(annonce_id));
}
以及
的服务@Override
public Optional<AnnonceDTO> getOne(UUID annonceId) {
if (!annonceRepository.existsById(annonceId))
throw new ElementNotFoundException();
return annonceRepository.findById(annonceId).map(annonceMapper::toDTO);
}
我试试邮递员
http://localhost:8080/annonce/0e7b4f11-b7eb-4c83-83e3-d08955ddd7ae
但是 return 为空,并且该行在我的 mysql 数据库中...
我没有错误,只是为空,我一直在寻找原因,但我没有找到,但还有一些事情要知道?...使用 UUID?...我已经看到了在我的数据库上,该行是 blob,我在数据库上尝试 select,这只适用于 unhex,但是在 spring 上,UUID 是 fonctionnaly inside ?..
有人可以帮助我,
非常感谢?..
这里也是mysql
我找到了在存储库上查询的解决方案....
@Query("SELECT CASE WHEN COUNT(a) > 0 THEN true ELSE false END FROM Annonce a WHERE a.annonce_id = :annonceId")
Boolean ifExistByUuid(@Param("annonceId") UUID annonce_id);
@Query("SELECT a FROM Annonce a WHERE a.annonce_id= ?1")
Annonce findOneByUuid(UUID annonce_id);
非常感谢您的帮助....工作正常....