I finally am getting back to this, and considered creating a new post, but I figure if anyone else needs this solved, this will show up.
I’ve created a simple webapp for testing this issue using Vaadin 24.4, Spring Boot 3.2.7, and Hibernate ORM 6.4.9.
I have a simple Entity
@Entity(name = "BasicEntity")
@Table(name = "basic_entity")
public class BasicEntity {
public BasicEntity() {
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
private UUID id;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
}
And a simple service
@Service
public class TestService {
private static final Logger log = LoggerFactory.getLogger(TestService.class);
@PersistenceContext
private EntityManager entityManager;
@Transactional
public void transact() {
BasicEntity basicEntity = new BasicEntity();
Session session = entityManager.unwrap(Session.class);
UUID id = (UUID) session.save("BasicEntity", basicEntity);
log.info("Saved BasicEntity: {}", id);
session.flush();
session.refresh(basicEntity);
basicEntity = (BasicEntity) session.get("BasicEntity", basicEntity.getId());
session.flush();
}
@Transactional
public void transact2() {
BasicEntity basicEntity = new BasicEntity();
Session session = entityManager.unwrap(Session.class);
session.persist("BasicEntity", basicEntity);
session.flush();
session.refresh(basicEntity);
basicEntity = (BasicEntity) session.getReference("BasicEntity", basicEntity.getId());
session.flush();
}
}
Both session.getReference and session.get throw the same
java.lang.IllegalArgumentException: Unable to locate persister: BasicEntity
Now if I change get/getReference to use the FQN: it works!
basicEntity = (BasicEntity) session.get("com.example.application.domain.BasicEntity", basicEntity.getId());
Same if I change the get/getReference to be BasicEntity.class, which I imagine is the far more common usage.
Configuration is pretty minimal, I use @EntityScan for BasicEntity’s package, and my application.yml is
spring:
datasource:
driverClassName: org.h2.Driver
url: jdbc:h2:${java.io.tmpdir}/test.db
username: sa
password:
jpa:
properties:
hibernate.hbm2ddl.auto: update