3
votes

I havea java maven3 project in Eclipse IDE with jboss tools installed. I'm using hibenrate4

I'm triing to setup the hibenrate configuratoin in hibernate view to test hql queries, the problem is that is says that it couldnt find the persistence unit. I have the persistence.xml placed in src/main/resources/META-INF/persistence.xml

is there some maven config that I nead to set?

project structure

hibenrate configuration

hibernate configuration

persistence unit not found error

Persistence.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.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
@Andrei It was wotking in previews projects, in eclipse juno with both files, now in kepler I have problems, I dont see the reason why both files should not be there - simonC
@simonC Is it not the case that if META-INF/persistence.xml is already on your classpath, you don't need to explicitly select a persistence unit? - JamesB
@JamesB is I remove the persistence unit entry from the hibernate edit configurations the problem persists, in this case it says "persistence unit not found : null" - simonC
@Andrei ... i nead hibernate-cfg.properties only for the purpouse of reverse engineering and hql query testing via jboss hibenrate tools in eclise, the aplication itself uses a datasource ... I have used many times both files in an aplication withowt problems - simonC
Do you have a single persistene.xml file in your project? Don't you have another one in test/resources/META_INF? PS: I deleted my comments as I do not consider them useful. - Andrei I

1 Answers

0
votes

You need a META-INF/persistence.xml with

<persistence-unit name="ypay">

(usually put it in WEB-INF/classes/META-INF. When using maven you can try placing it in src/main/resources/META-INF)

Please refer to this doc for details.