Lã Văn Thọ (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=60d9710...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYjY5ZjlkNDBj...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16484?atlOrigin=eyJpIjoiYjY5Zj...
) HHH-16484 (
https://hibernate.atlassian.net/browse/HHH-16484?atlOrigin=eyJpIjoiYjY5Zj...
) org.hibernate.UnknownEntityTypeException: Unable to locate entity descriptor:
com.game.data.core.entity.BaseEntity (
https://hibernate.atlassian.net/browse/HHH-16484?atlOrigin=eyJpIjoiYjY5Zj...
)
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Components: hibernate-core
Created: 18/Apr/2023 01:56 AM Environment: Java 17, Window 11 , MySQL 8.0.32 Priority:
Major Reporter: Lã Văn Thọ (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=60d9710...
)
Hello Guys, I have three class : *BaseEntity, User, DaoCore*
package com.game.data.core.entity; import jakarta.persistence.*; import lombok.Data;
import java.io.Serializable; import java.time.LocalDateTime;@MappedSuperclass@Datapublic
abstract class BaseEntity implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id; @Column(name = "created" , nullable = false ,
updatable = false )
protected LocalDateTime created; @Column(name = "updated" , nullable =
false )
protected LocalDateTime updated; public BaseEntity() {
this.created = LocalDateTime.now(); this.updated = LocalDateTime.now();
}
@PreUpdate public void preUpdate() {
this.updated = LocalDateTime.now(); }
}
*User* class :
package com.game.data.core.entity;
import jakarta.persistence.Entity;
import lombok.Data;
@Entity
@Data
public class User extends BaseEntity {
private String username;
private String password;
}
// DaoCore Class
package com.game.data.core.dao;
import com.game.data.core.entity.BaseEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DaoCore<T extends BaseEntity,ID extends Integer> extends
JpaRepository<T,ID> {
}
And AbstractServiceCRUD :
package com.game.data.core.base;
import com.game.data.core.entity.BaseEntity;
import com.game.data.core.dao.DaoCore;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.ArrayDeque;
@Service@Slf4j(topic = "AbstractServiceCRUD")
@Transactional(rollbackOn = RuntimeException.class)
@RequiredArgsConstructor
public class AbstractServiceCRUD<T extends BaseEntity, ID extends Integer>
implements ServiceCore<T, ID> {
private final DaoCore<T, ID> daoCore; @Override public T save(T bo) {
try {
log.info("saving data"); return daoCore.save(bo); }
catch (Exception e) {
log.error("error saving data", e); throw new
RuntimeException(e); }
}
@Override public T update(T bo, ID id) {
try {
if (!(id instanceof Integer)) {
log.info("id is not instance Integer"); return
null; }
boolean isExist = daoCore.existsById(id); if (isExist) {
log.info("updating data with id: {}", id);
bo.preUpdate(); return daoCore.save(bo); }
log.info("data with id: {} not found", id); return null;
} catch (Exception e) {
log.error("error updating data", e); throw new
RuntimeException(e); }
}
@Override public T delete(T bo) {
try {
ID id = (ID) bo.getId(); if (id != null) {
log.info("deleting data with id: {}", id);
daoCore.deleteById(id); return bo; }
log.info("data with id: {} not found", id); return null;
} catch (Exception e) {
log.error("error deleting data", e); throw new
RuntimeException(e); }
}
@Override public T findById(ID id) {
log.info("finding data with id: {}", id); T bo =
daoCore.findById(id).orElse(null); if (bo != null) {
log.info("data with id: {} found", id); return bo;
}
return null; }
@Override public ArrayDeque<T> findAll() {
log.info("finding all data"); return new
ArrayDeque<>(daoCore.findAll()); }
@Override public Page<T> findAll(Pageable pageable) {
log.info("finding all data with page {} and size {}",
pageable.getPageNumber(), pageable.getPageSize()); return
daoCore.findAll(pageable); }
}
And AbstractControllerCRUD :
package com.game.data.core.base;
import com.game.data.core.entity.BaseEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayDeque;
@RestController
@RequiredArgsConstructor
public class AbstractControllerCRUD<T extends BaseEntity, ID extends Integer>
implements ServiceCore<T, ID>{
@Autowired private AbstractServiceCRUD<T, ID> abstractServiceCRUD;
@PostMapping("/insert")
@Override public T save(@RequestBody T bo) {
return abstractServiceCRUD.save(bo); }
@PostMapping("/update/{id}")
@Override public T update( @RequestBody T bo,@PathVariable ID id) {
return abstractServiceCRUD.update(bo, id); }
@GetMapping("/delete/{id}")
@Override public T delete(@RequestBody T bo) {
return abstractServiceCRUD.delete(bo); }
@GetMapping("/find/{id}")
@Override public T findById(@PathVariable ID id) {
return abstractServiceCRUD.findById(id); }
@GetMapping("/findAll")
@Override public ArrayDeque<T> findAll() {
return abstractServiceCRUD.findAll(); }
@GetMapping("/findAllPage")
@Override public Page<T> findAll(@RequestBody Pageable pageable) {
return abstractServiceCRUD.findAll(pageable); }
}
And class : UserController
package com.game.data.core.endpoint;
import com.game.data.core.base.AbstractControllerCRUD;
import com.game.data.core.entity.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController@RequestMapping("/api/user")
public class UserController extends AbstractControllerCRUD<User,Integer> {
}
*When I call to api : /api/user/find/
{id}
it gives an error :* *org.hibernate.UnknownEntityTypeException: Unable to locate entity
descriptor: com.game.data.core.entity.BaseEntity*
*If I call API /api/user/insert it still works, please help me, thanks*
(
https://hibernate.atlassian.net/browse/HHH-16484#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16484#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100222- sha1:c08beee )