如何为Hibernate JPA创建一个persistence.xml文件?

编程入门 行业动态 更新时间:2024-10-15 12:36:29
本文介绍了如何为Hibernate JPA创建一个persistence.xml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图使用Hibernate JPA,但我需要创建我的persistence.xml(所以我可以正确使用实体管理器)。我不确定要创建什么以及将它放在哪里。

I'm trying to use Hibernate JPA but I need to create my persistence.xml (so I can use the entity manager correctly). I am unsure what to create and where to place it.

这就是我在'Core'模式下配置hibernate.cfg.xml的方式。 我正在使用:Eclipse Java EE IDE Web开发者版本:Indigo Release

This is how my hibernate.cfg.xml in 'Core' mode configured. I'm using : Eclipse Java EE IDE Web Developers version:Indigo Release

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "hibernate.sourceforge/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.password">XXXXXX</property> <property name="hibernate.connection.url">jdbc:mysql://<hostname>/<database></property> <property name="hibernate.connection.username">XXXXX</property> <property name="hibernate.default_schema">XXXXXX</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> </session-factory> </hibernate-configuration>

推荐答案

创建驻留在META中的persistence.xml文件-INF文件夹。

Create a persistence.xml file that resides in the META-INF folder.

示例:

Example:

<persistence xmlns="java.sun/xml/ns/persistence" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="java.sun/xml/ns/persistence java.sun/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="sample"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/DefaultDS</jta-data-source> <mapping-file>ormap.xml</mapping-file> <jar-file>MyApp.jar</jar-file> <class>org.acme.Employee</class> <class>org.acme.Person</class> <class>org.acme.Address</class> <properties> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.password">XXXXXX</property> <property name="hibernate.connection.url">jdbc:mysql://<hostname>/<database></property> <property name="hibernate.connection.username">XXXXX</property> <property name="hibernate.default_schema">XXXXXX</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> </properties> </persistence-unit> </persistence>

更多推荐

如何为Hibernate JPA创建一个persistence.xml文件?

本文发布于:2023-10-23 05:19:38,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建一个   何为   文件   Hibernate   JPA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!