저는 자바 초보자입니다. JTA 트랜잭션을 사용하여 지속 유닛을 구성하는 데 어려움이 있습니다. 이미 정의되고, 설정되고 채워지는 PostgreSQL 데이터베이스를 사용해야합니다. 넷빈즈를 사용하여, 나는 휴한지로 persistance.xml
및 glassfish-resources.xml
생성 :@PersistenceUnit을 사용하여 EntityManagerFactory를 주입하지 않습니다.
<persistence version="2.0" 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">
<persistence-unit name="WellWatcherPU" transaction-type="JTA">
<jta-data-source>WellWatcherDB</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/>
<property name="eclipselink.logging.level" value="FINE"/>
</properties>
</persistence-unit>
</persistence>
및
<resources>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.postgresql.ds.PGSimpleDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="post-gre-sql_geowellex_geowellexPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="5432"/>
<property name="databaseName" value="DBNAME"/>
<property name="User" value="USER"/>
<property name="Password" value="PASSWORD"/>
<property name="URL" value="jdbc:postgresql://localhost:5432/DBNAME"/>
<property name="driverClass" value="org.postgresql.Driver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="WellWatcherDB" object-type="user" pool-name="post-gre-sql_geowellex_geowellexPool"/>
</resources>
을 그리고 이것은 내가의 EntityManagerFactory와 EntityManager에 (넷빈즈 예에서 사용되는)
public class EUserDao {
@Resource
private UserTransaction utx = null;
@PersistenceUnit(unitName = "WellWatcherPU")
private EntityManagerFactory emf = null;
public EntityManager getEntityManager() {
return emf.createEntityManager(); <-------- NullPointerException here
}
public EUser getOne(long userId){
EntityManager em = getEntityManager();
try {
return em.find(EUser.class, userId);
} finally {
em.close();
}
}
을 얻는 방법이다
편집 :
여기 내 글라스가 있습니다. sfish 배포 로그 :
정보 : [EL Config] : 2012-05-10 12 : 01 : 13.534 - ServerSession (2017352940) - 연결 (1901223982) - 스레드 (스레드 [admin-thread-pool-4848 (5) (5), 그리즐리 커널]) - 연결 (DatabaseLogin ( 플랫폼 => DatabasePlatform 사용자 이름 = "" " 커넥터 => JNDIConnector 데이터 소스 이름 => 널 ))
Informações : EL 구성] : 2012-05-10 12 : 01 : 13.534 - ServerSession (2017352940) - 연결 (1462281761) - 스레드 (관리 쓰레드 - 풀 - 4848 (5), 5, 그리즐리 커널) -Connected : jdbc : postgresql : // localhost : 5432/geowellex? loginTimeout = 0 & prepareThreshold = 0 사용자 : g eowellex 데이터베이스 : PostgreSQL의 버전 : 9.1.3이 드라이버 : PostgreSQL의 기본 드라이버 버전 : PostgreSQL의 8.3 JDBC3 SSL과 ((603)를 구축)
Informações : [EL 구성] : 2012-05-10 12 : 01 : 13.534-- (DatabaseLogin ( 플랫폼 => PostgreSQLPlatform 사용자 이름 => 서버 세션) - 연결 (766700859) - 연결 (766700859) - 스레드 (스레드 [관리자 - 스레드 풀 4848 (5), 5, 그리즐리 커널] "" 커넥터 => JNDIConnector 데이터 소스 이름 => null ))
무엇이 잘못 되었습니까?
엔티티 관리자 팩토리의 초기화와 관련된 항목을 웹 서버 로그에서 게시하십시오. – Perception
방금 수정되었습니다. 도와 줘서 고마워. –