困扰了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();
}

}

求解决。。。。。。。。。。。。。。。
...全文
70 点赞 收藏 3
写回复
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日
说实话,看不懂
回复 点赞
发动态
发帖子
Web 开发
创建于2007-09-28

5.2w+

社区成员

34.1w+

社区内容

Java Web 开发
社区公告
暂无公告