[英]Configuring JTA in Tomcat7
I am using JEE5 with Postgresql, When I try to persist the object the output says我在 Postgresql 中使用 JEE5,当我尝试保留对象时,输出显示
Could not find datasource: java:jdbc/postgres javax.naming.NameNotFoundException: the name jdbc/postgres is not asociated with this context找不到数据源:java:jdbc/postgres javax.naming.NameNotFoundException:名称 jdbc/postgres 与此上下文无关
In context.xml (Tomcat7) I have在 context.xml (Tomcat7) 我有
<Context>
<Resource name="jdbc/postgres" auth="Container"
type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://127.0.0.1:5433/peopledb"
username="postgres" password="password" maxActive="20" maxIdle="10"
maxWait="-1"/>
</Context>
In persistence.xml I have:在persistence.xml 我有:
<persistence-unit name="People">
<jta-data-source>java:jdbc/postgres</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
In my persistence bean I have在我的持久性 bean 中,我有
@Stateless
public class PeopleDAOImpl implements PeopleDAO {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("People");
@Override
public void persistPeople(People pep) {
EntityManager em = emf.createEntityManager();
em.persist(pep);
}
}
Tomcat names the context resources differently than Glassfish. Tomcat 对上下文资源的命名与 Glassfish 不同。 You defined the name in context.xml
as jdbc/postgres
, but in the persistence.xml
you have to use java:comp/env/jdbc/postgres
.您在context.xml
中将名称定义为jdbc/postgres
,但在persistence.xml
您必须使用java:comp/env/jdbc/postgres
。
A late reply, but maybe still useful for others:迟到的回复,但可能对其他人仍然有用:
JTA can be used in Tomcat with componentized implementations like Atomikos ( https://www.atomikos.com ). JTA 可以在 Tomcat 中使用组件化实现,如 Atomikos ( https://www.atomikos.com )。
Cheers干杯
PS: if you want help in setting things up you may want to consider a free trial of Atomikos - which includes Tomcat support / setup. PS:如果您在设置方面需要帮助,您可能需要考虑免费试用 Atomikos - 其中包括 Tomcat 支持/设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.