我尝试使用以下方法进行简单的持久性测试: IntelliJ IDEA, Maven的, Google Guice, GWT, EclipseLink和JPA 2.0。
我的persistence.xml:
<persistence-unit name="guiceTest" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>utfpr.edu.br.server.model.Contato</class>
<properties>
<property name="javax.persistence.jdbc.url"
value="jdbc:postgresql://127.0.0.1:5432/gwt"/>
<property name="javax.persistence.jdbc.password" value="postgres"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
例外:
[EL Warning]: 2012-06-21 10:18:32.846--The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
java.lang.IllegalArgumentException: Object: Contato{dataNascimento=Thu Jun 21 10:18:31 BRT 2012, id=null, nome='abcd', sobrenome='adsada', numero='12313123', email='lololol@gmail.com'} is not a known entity type.
测试类:
Injector i = PersistenceTestModule.getInjector();
private ContatoDao dao = i.getInstance(ContatoDao.class);
@Test
public void testSave() throws Exception {
Contato cont = new Contato("abcd","adsada","12313123","lollollo@gmail.com",new Date());
dao.save(cont);
assertNotNull(cont.getId());
}
我的persistence.xml已更正放在resources / META-INF。
中我在这里看到这是一个eclipselink错误:https://bugs.eclipse.org/bugs/show_bug.cgi?id=338837
他们说:解决方案: 有两种方法可以解决这个问题。
1)我们根本没有指定实体,也没有指定 假 - 结果是一个完全空的元模型
2)我们只通过属性指定部分实体 - 这样做的结果是选择IllegalArgumentException错误时抛出 我们尝试使用缺少的EntityType类 - 可能在Criteria API中 查询&#34;
我已经尝试了这两个解决方案,但我仍然遇到了这个错误。
请有人帮助我!