EntityManager entityManager = Persistence.createEntityManagerFactory("examplePersistenceUnit") .createEntityManager(); MyEntity myEntity = entityManager.find(MyEntity.class, 1L); boolean isManaged = entityManager.contains(myEntity);In this example, we retrieve an instance of MyEntity with an ID of 1 from the database using the EntityManager's find() method. We then use the contains() method to check whether the entity instance is in the managed state. The javax.persistence.EntityManager interface is part of the Java Persistence API (JPA) library, which is typically included in the javax.persistence package in most Java applications.