有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

找不到java hibernate反向工程持久化单元

我在EclipseIDE中安装了一个JavaMaven3项目,并安装了jboss工具。我用的是hibenrate4

我想在hibernate视图中设置hibenrate配置来测试hql查询,问题是它找不到持久化单元。我有毅力。xml放在src/main/resources/META-INF/persistence中。xml

我需要设置一些maven配置吗

project structure

hibenrate configuration

hibernate configuration

persistence unit not found error

坚持。xml

   <persistence-unit  name="ypay">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:jboss/datasources/ypay</jta-data-source>
    <properties>
     <!-- Properties for Hibernate -->
     <!-- <property name="hibernate.hbm2ddl.auto" value="validate" /> -->
     <property name="hibernate.show_sql" value="false" />
     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />  
    </properties>

冬眠。属性

hibernate.connection.password=
hibernate.connection.username=root
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.connection.url=jdbc:mysql://****************:3306/ypay?useUnicode=true&amp;characterEncoding=UTF-8
hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider
hibernate.datasource=
hibernate.transaction.manager_lookup_class=

共 (1) 个答案

  1. # 1 楼答案

    你需要一个META-INF/persistence.xml

    <persistence-unit name="ypay">
    

    (通常将其放在WEB-INF/classes/META-INF中。使用maven时,可以尝试将其放在src/main/resources/META-INF中)

    详情请参阅thisdoc