Question

I'm going nuts trying to get a simple Envers example to work. I'm stuck on the org.hibernate.tool.ant.EnversHibernateToolTask — it looks like I finally got all the jar files I needed, but now I get the error message

[hibernatetool] Persistence unit not found: 'ConsolePU'.

BUILD FAILED
C:\deka\proj\java\test-database\build.xml:61: Persistence unit not found: 'ConsolePU'.

As far as I can tell, persistence units are associated with JPA persistence.xml files. But I'm not using a persistence.xml file; I'm using hibernate.cfg.xml — but the envers example has a <jpaconfiguration> in the ant task:

<hibernatetool destdir=".">
        <classpath>
             <fileset dir="src/">
                  <include name="**/*.hbm.xml"/>
            </fileset>

            <path location="${buildDir}" />
        </classpath>
    <jpaconfiguration persistenceunit="ConsolePU" />
    <hbm2ddl
        drop="false"
        create="true"
        export="false"
        outputfilename="versioning-ddl.sql"
        delimiter=";"
        format="true"/>
    </hibernatetool>

is there something that I can replace it with to get it to work with the hibernate.cfg.xml file? There seems to be ZERO documentation on how to get all this stuff to work properly.

edit: OK, so the main problem was I didn't understand the hibernatetool options and what was appropriate for my app. I did find the Hibernate ant docs, fortunately. Thanks. Now I have a new problem: I'm using annotations, but I also have set up a hibernate.cfg.xml for the properties settings. The hibernatetool task only lets me run either <configuration /> or <annotationconfiguration /> not both, and even <configuration /> won't work since I already have annotations doing things. How can I migrate my property settings from the hibernate.cfg.xml file to my annotations?

edit: Duh, I didn't realize you just do:

<annotationconfiguration configurationfile="...filename..." />

per the hibernatetool task docs.

Was it helpful?

Solution

Replace the <jpaconfiguration /> with the <configuration /> tag, as detailed in Hibernate Tools docs:

<configuration
    configurationfile="hibernate.cfg.xml"
    propertyfile="hibernate.properties"
    entityresolver="EntityResolver classname"
    namingstrategy="NamingStrategy classname">

OTHER TIPS

Just to give you high level prespective. JPA is standard persistence API provided by SUN.
You can use any persistence framework like Hibernate,TopLink,JDO etc as persistence provider with JPA.

So just to make things clear

Your code -----> JPA ----->Persistence Provider(Hibernate).

Its will be good practice to use JPA as it is standard library.

So what is your persistence provider information should only be known to JPA and not your code specific XML's.

This is how your persistence.xml will look like

<persistence version="1.0" 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">
<persistence-unit name="QuarkFrameworkPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
</persistence-unit>

And your Application context will look like (Dependent on JPA , no mention of Hibernate)

    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"
    p:driverClassName="com.mysql.jdbc.Driver" p:url="${db.url}" />




<!-- ADD PERSISTENCE SUPPORT HERE (jpa,etc) -->

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="QuarkFrameworkPU" />
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true" />
        </bean>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
    <property name="dataSource" ref="dataSource" />
</bean>

You need to start at the beginning: Sun's JPA tutorial.

This might help as well.

You need to create the persistence.xml and put it in the META-INF directory for your project.

Hibernate is one concrete implementation for JPA, but there are others (e.g., JDO).

You need annotationconfiguration not jpaconfiguration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top