JPA は初めてで、glassfish 3.1 で簡単な例を試してみたいと思っています。Bean 管理のトランザクションを使用していくつかのサンプル プログラムを実行できます。ただし、CMT で同じ例を試していると、トランザクションが必要な例外が発生します。
どこが間違っているのか手がかりが得られません。
私のプロジェクトは単純な Web プロジェクトで、エンティティ生成用の JPA ファセットを含めました。
私はEJBプロジェクトを使用していないため、glassfishアプリサーバーのEJBコンテナの機能を取得できないため、これが原因である可能性があります....これについてはわかりません...
以下のように私のpersitence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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="JPAPractise" transaction-type="JTA">
<jta-data-source>jdbc/JPAConnPool</jta-data-source>
<class>model.Address</class>
<class>model.Employee</class>
</persistence-unit>
トリガーポイントとしての通常のサーブレット:
@WebServlet("/TestJPA")
public class TestJPA extends HttpServlet {
private static final long serialVersionUID = 1L;
@PersistenceUnit
EntityManagerFactory emf;
/*@Resource
UserTransaction tx;*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
EntityManager em = emf.createEntityManager();
Employee e1 = new Employee();
e1.setEmployeeID("290874");
e1.setName("Shashi Shankar");
e1.setSalary(60000);
try{
//tx.begin();
em.persist(e1);
em.flush();
//tx.commit();
}catch(Exception e){
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
本当の問題を知るのを手伝ってください。