나는 스프링을 사용하지 않으므로 클래스 내에 EntityManager의 인스턴스를 만들고있다.Hibernate EntityManager, 그것이 싱글 톤으로 사용되어야합니까?
클래스를 자동 생성하기 위해 Hibernate-Eclipse 리버스 엔지니어링을 사용했습니다. 이러한 클래스에는 모두 EntityManager의 인스턴스가 있습니다.
Hibernate가 EntityManager와 함께 작동하는 방법을 100 % 확신하지 못해서,이 클래스 (EntityManager)의 인스턴스가 너무 많아서 트랜잭션에 문제가 있을지 궁금하다.
다른 모든 클래스에 대해 EntityManager의 정적 인스턴스를 배포하는 별도의 클래스를 만들어야합니까? 아니면 상관 없습니까?
EDIT : @PersistenceContext라고하는 뭔가가 있습니다. 인스턴스 변수에 내 persistence.xml을 bean으로로드하지 않는 것 같습니다.이 기능에는 스프링이 필요합니까? 나는 당신이 종속성을 필요
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="mypassword"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/ptbrowserdb"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
</persistence-unit>
</persistence>
('EntityManager '에서) 개인 액세스 수정자를 제거하고 테스트 할 수 있습니까? – Santosh