- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我第一次使用 hibernate/JPA2。我收到“无法构建 EntityManagerFactory”。能告诉我问题出在哪里吗?
这是我的 persistence.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="pdfEx" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>iw.pdfEx.persistence.Pdf</class>
<class>iw.pdfEx.persistence.XmlConversion</class>
<properties>
<property name="hibernate.connection.username" value="icite"/>
<property name="hibernate.connection.password" value="${hpass}"/>
<property name="hibernate.connection.url" value="${hurl}"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
这是我的测试类:
public class PersistenceTest {
private static EntityManagerFactory emf;
private static EntityManager em;
private static String randomPDFname;
private static String randomGITversion;
private static long sysTime = 0;
@BeforeClass
public static void createEntityManagerFactory() {
Logger.getLogger(FileConverter.class.getName()).log(Level.INFO, "hibernate URL is "+System.getProperty("hurl"));
Logger.getLogger(FileConverter.class.getName()).log(Level.INFO, "the path to pdf2xml is "+System.getProperty("pdf2xml"));
emf = Persistence.createEntityManagerFactory("pdfEx");
Logger.getLogger(FileConverter.class.getName()).log(Level.INFO, "PersistenceTest: EM factory created!");
randomPDFname = "random-pdf-name-"+UUID.randomUUID().toString();
randomGITversion = "random-git-version-"+UUID.randomUUID().toString();
sysTime = Math.round(System.currentTimeMillis()/((10^3)*3600));//systime in hours, rather than millisecs
}
@Before
public void beginTransaction() {
em = (EntityManager) Persistence.createEntityManagerFactory("pdfEx").createEntityManager();
em.getTransaction().begin();
}
@After
public void rollbackTransaction() {
if (em.getTransaction().isActive())
em.getTransaction().rollback();
if (em.isOpen())
em.close();
}
@AfterClass
public static void closeEntityManagerFactory() {
emf.close();
}
@Test
public void dbTest() {
//fail("Not yet implemented");
Pdf testPdf = new Pdf();
testPdf.setName(randomPDFname);
testPdf.setSize(sysTime);
//check that testPDF is, indeed, not yet in the DB:
Query getPDF = em.createNamedQuery("Pdf.Queries.PdfByNameAndSize");
getPDF.setParameter("pdfname", testPdf.getName());
getPDF.setParameter("pdfsize", testPdf.getSize());
List foundPDFs = getPDF.getResultList();
assertTrue("Random PDF "+randomPDFname+" is already in the DB", foundPDFs == null || foundPDFs.size() == 0 );
//persist testPdf in the DB
em.persist(testPdf);
//em.flush();
Logger.getLogger(FileConverter.class.getName()).log(Level.INFO, "Persisted testPdf");
//retrieve testPdf from the DB
Pdf thePDF = (Pdf) getPDF.getSingleResult();//trying to re-run the query
//and use it as a reference in a new XmlConversion
XmlConversion testXml = new XmlConversion();
testXml.setGitVersion(randomGITversion);
testXml.setPdf(thePDF);
testXml.setXmlOutputSize(sysTime);
//verify there is no such XmlConversion
Query getXML = em.createNamedQuery("XmlConversion.Queries.XmlByPdfAndGit");
getXML.setParameter("pdfname", testXml.getPdf());
getXML.setParameter("gitversion", testXml.getGitVersion());
List foundXMLs = getXML.getResultList();
assertTrue("XmlConversion is already in the DB", foundXMLs == null || foundXMLs.size() == 0 );
//store XmlConversion in the DB
em.persist(testXml);
//em.flush();
//retrieve XmlConversion from the DB
foundXMLs = getXML.getResultList();
assertTrue("XmlConversion is not in the DB", foundXMLs.size() == 1);
Logger.getLogger(FileConverter.class.getName()).log(Level.INFO, "PersistenceTest successful!");
}
}
这里是持久实体之一:
@Entity @NamedQuery(
name="Pdf.Queries.PdfByNameAndSize",
query="SELECT c FROM Pdf c WHERE c.name = :pdfname AND c.size = :pdfsize") @Table(name = "t_pdf") public class Pdf implements java.io.Serializable { @Column(nullable=false)
private Integer id;
@Column(nullable=false)
private String name;
@Column(nullable=false)
private Long size;
private Set<XmlConversion> xmlConversions = new HashSet<XmlConversion>(0);
public Pdf() {
}
public Pdf(String name, Long size) {
this.name = name;
this.size = size;
}
public Pdf(String name, Long size, Set<XmlConversion> xmlConversions) {
this.name = name;
this.size = size;
this.xmlConversions = xmlConversions;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "name", nullable = false, length = 245)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "size", nullable = false, length = 16777215)
public Long getSize() {
return this.size;
}
public void setSize(Long size) {
this.size = size;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "pdf")
public Set<XmlConversion> getXmlConversions() {
return this.xmlConversions;
}
public void setXmlConversions(Set<XmlConversion> xmlConversions) {
this.xmlConversions = xmlConversions;
}
这是另一个:
@Entity @NamedQuery(
name="XmlConversion.Queries.XmlByPdfAndGit",
query="SELECT c FROM XmlConversion c WHERE c.pdf = :pdfname AND c.gitVersion = :git" ) @Table(name = "t_xml_conversion") public class XmlConversion implements java.io.Serializable {
private Integer id;
private Pdf pdf;
private Long xmlOutputSize;
private String gitVersion;
private Integer durationMillisec;
private Date createdAt;
public XmlConversion() {
}
public XmlConversion(Pdf pdf, String gitVersion) {
this.pdf = pdf;
this.gitVersion = gitVersion;
}
public XmlConversion(Pdf pdf, Long xmlOutputSize, String gitVersion,
Integer durationMillisec) {
this.pdf = pdf;
this.xmlOutputSize = xmlOutputSize;
this.gitVersion = gitVersion;
this.durationMillisec = durationMillisec;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PDF_id", nullable = false)
public Pdf getPdf() {
return this.pdf;
}
public void setPdf(Pdf pdf) {
this.pdf = pdf;
}
@Column(name = "xml_output_size")
public Long getXmlOutputSize() {
return this.xmlOutputSize;
}
public void setXmlOutputSize(Long xmlOutputSize) {
this.xmlOutputSize = xmlOutputSize;
}
@Column(name = "git_version", nullable = false, length = 45)
public String getGitVersion() {
return this.gitVersion;
}
public void setGitVersion(String gitVersion) {
this.gitVersion = gitVersion;
}
@Column(name = "duration_millisec")
public Integer getDurationMillisec() {
return this.durationMillisec;
}
@Column(name = "created_at", nullable = false, columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
public Date getCreatedAt() {
return this.createdAt;
}
public void setDurationMillisec(Integer durationMillisec) {
this.durationMillisec = durationMillisec;
}
以下是 Maven 依赖项:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.3.Final</version>
<scope>runtime</scope>
</dependency>
当我尝试“maven test”时,我得到:
iw.pdfEx.PersistenceTest Time elapsed: 3.156 sec <<< ERROR! javax.persistence.PersistenceException: [PersistenceUnit: pdfEx] Unable to build EntityManagerFactory
at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:252)
at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:245)
at org.hibernate.mapping.Property.getSetter(Property.java:326)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:444)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:201)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:82)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:341)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:507)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:146)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:385)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:59)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at iw.pdfEx.PersistenceTest.createEntityManagerFactory(PersistenceTest.java:42)
这是我在 Surefire 报告中找到的测试输出:
Jul 28, 2013 12:11:25 PM iw.pdfEx.PersistenceTest createEntityManagerFactory
INFO: hibernate URL is jdbc:mysql://localhost:8600/icite Jul 28, 2013 12:11:25 PM iw.pdfEx.PersistenceTest createEntityManagerFactory
INFO: the path to pdf2xml is /home/nikolay/Documents/invoiceFairy/pdf2xml/pdftoxml.linux64.exe.1.2_7 Jul 28, 2013 12:11:26 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final} Jul 28, 2013 12:11:26 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.3.Final} Jul 28, 2013 12:11:26 PM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found Jul 28, 2013 12:11:26 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Jul 28, 2013 12:11:27 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) Jul 28, 2013 12:11:27 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 Jul 28, 2013 12:11:27 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true Jul 28, 2013 12:11:27 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:8600/icite] Jul 28, 2013 12:11:27 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=icite, password=****, autocommit=true, release_mode=auto} Jul 28, 2013 12:11:27 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect Jul 28, 2013 12:11:28 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory Jul 28, 2013 12:11:28 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
最佳答案
您没有为 XmlConversion
的属性 createdAt
定义任何 setter 方法。
关于mysql - hibernate 、JPA、MySQL : Unable to build EntityManagerFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17908940/
这个问题在这里已经有了答案: android studio adb Syntax error: ")" unexpected (4 个答案) 关闭 5 年前。 我确实将我的工作室更新到 Linux
当我打开 Android Studio 时,它会显示下面的对话框,我的应用程序无法以 Debug模式运行。 最佳答案 找到sdk->platform-tool文件夹,然后运行命令adb tcpip 5
我在 Fedora 33 机器上使用了 VSCode (1.52.1) 一段时间。 我正在使用 Docker 扩展 (v1.9.0) 但由于某种原因,在过去几天中,当我尝试将 VSCode 附加到 D
我正在尝试为我的任务加载一个名为“tr_model.h5”的预训练模型,但出现以下错误: Traceback (most recent call last): File "Trigger_Proje
我最近在 Google Play 中发布了一个 Android 应用程序,到目前为止一切看起来都很棒,但有一个异常(exception)(见下文),我有时会收到控制台崩溃的消息,它只发生在某些用户身上
单击警告时,我收到此消息。这是案件的截图。 错误写道, Unable to open 'warning.cpp': Unable to read file '/Users/dimen/code/C++
重新编译 php 后,当我使用 php cli 时出现以下错误: PHP Warning: PHP Startup: imap: Unable to initialize module Module
使用 git 1.6.4.2,当我尝试 git pull 时出现此错误: error: unable to resolve reference refs/remotes/origin/LT558-op
我是 Kotlin 的新手,我正在学习教程。运行我的应用程序会导致它在运行时崩溃。我在底部导航栏应用程序中有三个 fragment 和一个主要 Activity 。我的目标实际上只是成功运行该应用程序
我在 Windows 10 64 位上运行 Android Studio。我在 5 月 20 日早上升级到了最新的版本和 SDK,从那时起,我在打开 Android Studio 时收到上述错误。我还
因此,我创建了一个 GitHub 操作,该操作应该在发生推送时构建 docker 镜像并将其推送到 docker hub。所以这是我的 GitHub 操作:(第一次创建 GitHub 操作) name
当这些问题中的任何一个都没有帮助我时,这意味着我需要删除并重新安装 Android Studio。 这是错误: Error initializing ADB: Unable to create Deb
Iam running the latest OSX/Flutter/XCode Versions using flutter, android studio and firebase and
我最近重新安装了 ubuntu 20.04.3,在做了一些设置后,我现在在运行 apt update 时总是收到以下错误.我一定是不小心删除了某种缓存文件或目录,但我不知道如何诊断或解决这个问题。 任
今天,当我将更改推送到 Gitlab 中的代码存储库时,我才开始在 Gitlab 中收到此错误消息。 Gitlab fatal: unable to access '.......' SSL Cert
我正在使用 Protractor 和 Jasmine 。 我已经确定了 chrome 驱动程序版本:2.32.498550 (latest)与 Chrome 测试版不兼容 (Version 62.0.
我正在尝试使用 terraform (0.12.24) 和多个 Docker 提供程序(插件版本 2.7.0)执行简单部署。我使用下面的 Terraform 模板的目的是将两个不同的容器部署到两个不同
这个问题我看了很久,最后决定在这里提出来。我需要维护一些用 Delphi 2007 for .NET (ASP.NET 2.0) 编写的应用程序。通常,第一次运行应用程序(使用 IIS)时,我会收到经
如何修复 - 无法创建调试桥:无法启动 adb 服务器:无法检测 adb 版本,adb 输出:/home/dilip/Downloads/sdk/platform-tools/adb: 1:/home
通过命令提示符连接到 android 中的 Sqlite DB 时出现错误。 以下是我遵循的步骤: 我已经在 android 中通过 java 程序创建了 Sqlite 数据库。创建表并向其中插入数据
我是一名优秀的程序员,十分优秀!