大家好!
我使用spring + jpa。在TomEE服务器上运行它。在tomee文件中,我有正确的数据源到我的MySQL服务器。当我执行entityManager的持久化操作时,我会收到此日志
2015-05-01 01:57:46,740 DEBUG [http-bio-8080-exec-2]
implementations.CommonDaoImpl (CommonDaoImpl.java:42) - save method ended success
2015-05-01 02:22:09,697 DEBUG [http-bio-8080-exec-2] implementations.CommonDaoImpl (CommonDaoImpl.java:32) - getById method started with id=1
[EL Finer]: 2015-05-01 02:22:09.698--ServerSession(160948815)--Thread(Thread[http-bio-8080-exec-2,5,main])--client acquired: 1920349854
[EL Finer]: 2015-05-01 02:22:09.698--ClientSession(1920349854)--Thread(Thread[http-bio-8080-exec-2,5,main])--acquire unit of work: 788265415
[EL Finest]: 2015-05-01 02:22:09.698--UnitOfWork(788265415)--Thread(Thread[http-bio-8080-exec-2,5,main])--Execute query ReadObjectQuery(name="readUser" referenceClass=User sql="SELECT LOGIN, FIRSTNAME, MIDDLENAME, PASSWORD, SECONDNAME FROM USER WHERE (LOGIN = ?)")
[EL Finest]: 2015-05-01 02:22:09.698--ServerSession(160948815)--Connection(550211562)--Thread(Thread[http-bio-8080-exec-2,5,main])--Connection acquired from connection pool [read].
[EL Finest]: 2015-05-01 02:22:09.698--ServerSession(160948815)--Thread(Thread[http-bio-8080-exec-2,5,main])--reconnecting to external connection pool
[EL Fine]: 2015-05-01 02:22:09.699--ServerSession(160948815)--Connection(341138552)--Thread(Thread[http-bio-8080-exec-2,5,main])--SELECT LOGIN, FIRSTNAME, MIDDLENAME, PASSWORD, SECONDNAME FROM USER WHERE (LOGIN = ?)
bind => [1]
[EL Finest]: 2015-05-01 02:22:09.703--ServerSession(160948815)--Connection(550211562)--Thread(Thread[http-bio-8080-exec-2,5,main])--Connection released to connection pool [read].
[EL Finer]: 2015-05-01 02:22:09.703--UnitOfWork(788265415)--Thread(Thread[http-bio-8080-exec-2,5,main])--release unit of work
[EL Finer]: 2015-05-01 02:22:09.703--ClientSession(1920349854)--Thread(Thread[http-bio-8080-exec-2,5,main])--client released
2015-05-01 02:22:09,703 DEBUG [http-bio-8080-exec-2] implementations.CommonDaoImpl (CommonDaoImpl.java:34) - getById method ended with obj=null
2015-05-01 02:22:09,712 DEBUG [http-bio-8080-exec-2] implementations.UserServiceImpl (UserServiceImpl.java:47) - saveNotActivatedUser method started with user = 1[1, null, 1][STUDENT, STUDENT]
2015-05-01 02:22:09,713 DEBUG [http-bio-8080-exec-2] implementations.CommonDaoImpl (CommonDaoImpl.java:40) - save method started with entity=1[1, null, 1][STUDENT, STUDENT]
[EL Finer]: 2015-05-01 02:22:09.714--ServerSession(160948815)--Thread(Thread[http-bio-8080-exec-2,5,main])--client acquired: 1983904739
[EL Finer]: 2015-05-01 02:22:09.714--ClientSession(1983904739)--Thread(Thread[http-bio-8080-exec-2,5,main])--acquire unit of work: 1655845051
[EL Finest]: 2015-05-01 02:22:09.714--UnitOfWork(1655845051)--Thread(Thread[http-bio-8080-exec-2,5,main])--persist() operation called on: 1[1, null, 1][STUDENT, STUDENT].
[EL Finer]: 2015-05-01 02:22:09.716--UnitOfWork(1655845051)--Thread(Thread[http-bio-8080-exec-2,5,main])--release unit of work
[EL Finer]: 2015-05-01 02:22:09.716--ClientSession(1983904739)--Thread(Thread[http-bio-8080-exec-2,5,main])--client released
2015-05-01 02:22:09,716 DEBUG [http-bio-8080-exec-2] implementations.CommonDaoImpl (CommonDaoImpl.java:42) - save method ended success
2015-05-01 02:22:09,716 DEBUG [http-bio-8080-exec-2] implementations.UserServiceImpl (UserServiceImpl.java:49) - saveNotActivatedUser method ended successfull
2015-05-01 02:22:09,717 DEBUG [http-bio-8080-exec-2] implementations.CommonDaoImpl (CommonDaoImpl.java:40) - save method started with entity=entity.Activation@209d779c
[EL Finer]: 2015-05-01 02:22:09.717--ServerSession(160948815)--Thread(Thread[http-bio-8080-exec-2,5,main])--client acquired: 1108849534
[EL Finer]: 2015-05-01 02:22:09.717--ClientSession(1108849534)--Thread(Thread[http-bio-8080-exec-2,5,main])--acquire unit of work: 571029272
[EL Finest]: 2015-05-01 02:22:09.718--UnitOfWork(571029272)--Thread(Thread[http-bio-8080-exec-2,5,main])--persist() operation called on: entity.Activation@209d779c.
[EL Finer]: 2015-05-01 02:22:09.722--UnitOfWork(571029272)--Thread(Thread[http-bio-8080-exec-2,5,main])--release unit of work
[EL Finer]: 2015-05-01 02:22:09.723--ClientSession(1108849534)--Thread(Thread[http-bio-8080-exec-2,5,main])--client released
2015-05-01 02:22:09,723 DEBUG [http-bio-8080-exec-2] implementations.CommonDaoImpl (CommonDaoImpl.java:42) - save method ended success
看起来一切都是正确的。但在我的数据库中没有一个数据行。
这是我的persistence.xml
<persistence-unit name="joyUnit">
<class>entity.User</class>
<class>entity.Activation</class>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>JoyDS</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"></property>
<property name="eclipselink.ddl-generation.output-mode" value="database"></property>
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.jdbc.cache-statements" value="true"></property>
<property name="eclipselink.logging.parameters" value="true" />
</properties>
</persistence-unit>
或者有人可以告诉我如何在java中执行绑定jta-data-sources。因为我不了解JTA交易类型。 这段代码在春天发现了什么?
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="joyUnit" />
</bean>
我认为连接到内部数据库但在我看到的日志中
[EL Config]: 2015-05-01 01:57:46.33--ServerSession(160948815)--Connection(692349912)--Thread(Thread[http-bio-8080-exec-2,5,main])--connecting(DatabaseLogin(
platform=>DatabasePlatform
user name=> ""
connector=>JNDIConnector datasource name=>null
))
[EL Config]: 2015-05-01 01:57:46.331--ServerSession(160948815)--Connection(2016054357)--Thread(Thread[http-bio-8080-exec-2,5,main])--Connected: jdbc:mysql://localhost/joy
User: user@localhost
Database: MySQL Version: 5.6.20
Driver: MySQL Connector Java Version: mysql-connector-java-5.1.31 ( Revision: alexander.soklakov@oracle.com-20140520065950-groqzzbvxprqdmnz )
[EL Finest]: 2015-05-01 01:57:46.332--ServerSession(160948815)--Connection(828595733)--Thread(Thread[http-bio-8080-exec-2,5,main])--Connection acquired from connection pool [read].
[EL Finest]: 2015-05-01 01:57:46.332--ServerSession(160948815)--Connection(828595733)--Thread(Thread[http-bio-8080-exec-2,5,main])--Connection released to connection pool [read].
[EL Config]: 2015-05-01 01:57:46.332--ServerSession(160948815)--Connection(1924517383)--Thread(Thread[http-bio-8080-exec-2,5,main])--connecting(DatabaseLogin(
platform=>MySQLPlatform
user name=> ""
connector=>JNDIConnector datasource name=>null
))
[EL Config]: 2015-05-01 01:57:46.338--ServerSession(160948815)--Connection(37511204)--Thread(Thread[http-bio-8080-exec-2,5,main])--Connected: jdbc:mysql://localhost/joy
User: user@localhost
Database: MySQL Version: 5.6.20
Driver: MySQL Connector Java Version: mysql-connector-java-5.1.31 ( Revision: alexander.soklakov@oracle.com-20140520065950-groqzzbvxprqdmnz )
有人可以解释为什么db登录设置3次???
因为前段时间我可以在没有类路径中的persistence.xml文件的情况下正确地写入数据库,但是必须使用名称&#39; joyUnit&#39;
来访问数据源