JSF2.0+JPA2.0+eclipse 構築編:JPAでの例外の解消(その2)
前々回から苦しんでいる例外の原因、さっぱり分かりません。
ちょっと目先を変えて、persistence.xmlの書き方がまちがってないことを確認しておきます。
テスト用mainメソッドの作成
EmployeeServiceにmainメソッドを作ってgetAllメソッドを呼び出してみましょう。
JavaEEコンテナに頼らず、自前でJPAのAPIを使ってみます。
public static void main(final String[] args) { final EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu"); try { final EntityManager em = emf.createEntityManager(); final EmployeeService es = new EmployeeService(); es.em = em; final List<Employee> list = es.getAll(); System.out.println(list); } finally { emf.close(); } }
実行すると・・・
2011/02/08 0:10:49 org.hibernate.validator.util.Version <clinit> 情報: Hibernate Validator null 2011/02/08 0:10:49 org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA 情報: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver. [EL Info]: 2011-02-08 00:10:50.187--ServerSession(1911628635)--EclipseLink, version: Eclipse Persistence Services - 2.0.1.v20100213-r6600 [EL Info]: 2011-02-08 00:10:51.341--ServerSession(1911628635)--file:/Users/jabaraster/Documents/workspace/sandbox-glassfish-embedded/WebContent/WEB-INF/classes/_pu login successful [EL Fine]: 2011-02-08 00:10:51.368--ServerSession(1911628635)--Connection(1931890953)--DROP TABLE EMPLOYEE [EL Fine]: 2011-02-08 00:10:51.636--ServerSession(1911628635)--Connection(1931890953)--CREATE TABLE EMPLOYEE (ID BIGINT NOT NULL, NAME VARCHAR(120) NOT NULL, PRIMARY KEY (ID)) [EL Fine]: 2011-02-08 00:10:51.71--ServerSession(1911628635)--Connection(1931890953)--CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME)) [EL Fine]: 2011-02-08 00:10:51.723--ServerSession(1911628635)--VALUES(1) [EL Warning]: 2011-02-08 00:10:51.804--ServerSession(1911628635)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Table/View 'SEQUENCE' は、既に Schema 'USER' に存在します。 Error Code: 30000 Call: CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME)) Query: DataModifyQuery(sql="CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))") [EL Fine]: 2011-02-08 00:10:51.806--ServerSession(1911628635)--Connection(1931890953)--DELETE FROM SEQUENCE WHERE SEQ_NAME = SEQ_GEN [EL Fine]: 2011-02-08 00:10:51.886--ServerSession(1911628635)--Connection(1931890953)--SELECT * FROM SEQUENCE WHERE SEQ_NAME = SEQ_GEN [EL Fine]: 2011-02-08 00:10:51.9--ServerSession(1911628635)--Connection(1931890953)--INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values (SEQ_GEN, 0) [EL Fine]: 2011-02-08 00:10:52.041--ServerSession(1911628635)--Connection(1931890953)--SELECT ID, NAME FROM EMPLOYEE [] [EL Info]: 2011-02-08 00:10:52.051--ServerSession(1911628635)--file:/Users/jabaraster/Documents/workspace/sandbox-glassfish-embedded/WebContent/WEB-INF/classes/_pu logout successful
ちゃんと動いてる。
ちゃんとテーブルCREATEのSQL文も発行されています。
persistence.xmlに誤りはないようです。
うーん、次は何を調べようかな・・・