2012-02-24 2 views
0

* で注入したときのEntityManagerがnullである私が代わりにサーブレットのプロジェクト作業のようなRPCの別のものを使用しnull.ifおそらく *私はGlassFishのEntityManagerの中でプロジェクトを展開するときのGlassFish

セッションBeanは、次のとおりです。

@Stateless 

public class logic implements logicLocal { 

    @PersistenceContext(unitName="T2PU") 
    private EntityManager em; 

    @Override 
    public void addToDB(Test t){ 

     em.persist(t); 
    } 

} 

とGWT RPCは:

public class MainRPCImpl extends RemoteServiceServlet implements MainRPC { 

    @EJB 
    logicLocal logic; 


    @Override 
    public String addToDB(Test t) { 
     String m="fail"; 
     try { 
      logic.addToDB(t); 
      m="done successfuly"; 
     } catch (Exception e) { 
      return m; 
     } 
     return m; 
    } 
} 

永続ユニットは:

<persistence-unit name="T2PU" transaction-type="JTA"> 
    <jta-data-source>acm</jta-data-source> 
    <exclude-unlisted-classes>false</exclude-unlisted-classes> 
    <properties/> 
    </persistence-unit> 
</persistence> 

とGlassFish資源

<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="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" 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="mysql_acm_rootPool" 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="3306"/> 
     <property name="databaseName" value="acm"/> 
     <property name="User" value="root"/> 
     <property name="Password" value="1234"/> 
     <property name="URL" value="jdbc:mysql://localhost:3306/acm"/> 
     <property name="driverClass" value="com.mysql.jdbc.Driver"/> 
    </jdbc-connection-pool> 
    <jdbc-resource enabled="true" jndi-name="acm" object-type="user" pool-name="mysql_acm_rootPool"/> 
</resources> 

事前に特別に感謝します。

答えて

0

多分、理由はありますが、persistence.xmlのJNDI名にjdbcコンテキスト接頭辞を使用する必要はありませんか?このような何か:Glassfish administration guideから

<jta-data-source>jdbc/acm</jta-data-source> 

A JDBCリソースは、リソースが関連付けられます で接続プールを指定して作成されます。リソースを識別するには、一意のJava Namingおよび ディレクトリ・インターフェース(JNDI)名を使用します。 ... すべてのJNDI名がjava:comp/envサブコンテキストにあるため、 をAdministration ConsoleでJDBCリソースのJNDI名に指定するときは、 のjdbc/name形式のみを使用します。

+0

ご返信ありがとうございます。私がDTOを使用し、エンティティを直接プロジェクトのプロジェクトを正しく使用していないときは、エンティティから直接使用する考えはありますか? – hesam

関連する問題