困扰了2天的jpa问题,求高手解答

qq84299 2013-06-26 04:05:42
问题如下:
Exception in thread "main" javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at com.gg.Test.main(Test.java:11)
Caused by: org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:70)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:89)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:222)
... 4 more





persistence.xml文件

<?XML version="1.0"?>
<persistence 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_1_0.xsd" version="1.0">
<!-- 实体bean集合 和数据库进行映射 -->
<!-- RESOURCE_LOCAL 本地事物 -->
<persistence-unit name="aa" transaction-type="RESOURCE_LOCAL">
<!-- hibernate 配置 -->
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.gjt.mm.mysql.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="123456"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
</properties>
</persistence-unit>
</persistence>

实体类:
package com.gg;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
* @Entity标注实体bean
*@Id主键
*@GeneratedValue增长方式
*/
@Entity
public class Person {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;

private String name;

public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}



测试类:

package com.gg;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;


public class Test {
public static void main(String[] args) {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("aa");
EntityManager em = factory.createEntityManager();
EntityTransaction et = em.getTransaction();
et.begin();
// em.persist(new Person("大连"));
et.commit();
em.close();
factory.close();
}

}

求解决。。。。。。。。。。。。。。。
...全文
106 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
关键我是洛哥 2013-06-28
  • 打赏
  • 举报
回复
应该是你的persistence.xml文件 有问题 Caused by: org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed 参考:http://hi.baidu.com/_cafebaby/item/409f280d0ae95512acdc7021
调皮的芋头 2013-06-28
  • 打赏
  • 举报
回复
<?XML version="1.0"?>有问题,应该改为: <?xml version="1.0" encoding="UTF-8" ?>
最美的词 2013-06-26
  • 打赏
  • 举报
回复
说实话,看不懂

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧