Annotation mapping of Hibernate entities stopped working with the 1.0-milestone-4 release and is still a problem in 1.0-milestone-7

Annotation mapping of Hibernate entities stopped working with the 1.0-milestone-4 release and is still a problem in 1.0-milestone-7.

The command “gradle clean test” will allow the single unit-test included below to pass when using the following gradle versions: 0.9.2, 1.0-milestone-1, 1.0-milestone-2, 1.0-milestone-3. The same unit-test and fail in all versions 1.0-milestone-4 and above.

I can work around the issue by using gradle 1.0-milestone-3, or by adding an xml file to configure the Hibernate entities rather than using annotations. I suspect this issues goes into the core of gradle, and is not really related to Hibernate, and that is why I chose to post the problem here first. I noticed there was another related forum post marked as “solved”, where the solution was described as using xml configuration, which I feel is really a workaround, and not a solution to whatever the underlying problem is.

Thank you for a great piece of software, I hope this report will help improve this great build system even further.

Here follows the complete file structure and file contents of a small hello-world hibernate project that demonstrate the issue.


apply plugin: ‘java’

apply plugin: ‘eclipse’

repositories {



dependencies {

compile ‘org.hibernate:hibernate-entitymanager:3.6.1.Final’

compile ‘org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final’

compile (‘log4j:log4j:1.2.16’) {

exclude group: ‘com.sun.jdmk’, module: ‘jmxtools’

exclude group: ‘com.sun.jmx’, module: ‘jmxri’

exclude group: ‘javax.jms’,

module: ‘jms’


runtime ‘org.slf4j:slf4j-log4j12:1.6.1’

testCompile ‘junit:junit:4.8.1’

testRuntime ‘hsqldb:hsqldb:’



package foo;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;


public class Bar {



private int id;

private String greeting;

public Bar() {


public Bar(String greeting) {

this.greeting = greeting;


public int getId() {

return id;


public String getGreeting() {

return greeting;




package foo;

import java.util.concurrent.Callable;

class BarDao {

public Bar findTheBar(final Database db) throws Exception {

return db.callInTransaction(new Callable() {

public Bar call() throws Exception {

return db.getEntityManager().find(Bar.class, 1);






package foo;

import java.util.concurrent.Callable;

import javax.persistence.EntityManager;

import javax.persistence.EntityTransaction;

public class Database {

private final EntityManager entityManager;

public Database(EntityManager entityManager) {

this.entityManager = entityManager;


public EntityManager getEntityManager() {

return entityManager;


public T callInTransaction(Callable c) throws Exception {

EntityTransaction trans = entityManager.getTransaction();


try {

T result =;


return result;

} finally {

if (trans.isActive()) {








package foo;

import java.util.Properties;

import java.util.concurrent.Callable;

import javax.persistence.EntityManager;

import javax.persistence.EntityManagerFactory;

import javax.persistence.Persistence;

import org.apache.log4j.PropertyConfigurator;

import org.junit.Before;

import org.junit.Test;

public class BarDaoTest {

private Database db;


public void before() throws Exception {

// initialize log4j

Properties props = new Properties();

props.put(“log4j.appender.console”, “org.apache.log4j.ConsoleAppender”);

props.put(“log4j.appender.console.layout”, “org.apache.log4j.PatternLayout”);

props.put(“log4j.appender.console.layout.ConversionPattern”, “[%c %p] %m \n”);

props.put(“log4j.rootLogger”, “DEBUG, console”);

props.put(“”, “INFO”);


// initialize persistence

EntityManagerFactory emf = Persistence.createEntityManagerFactory(“unittest”);

EntityManager em = emf.createEntityManager();

db = new Database(em);

// fill database with test data

db.callInTransaction(new Callable() {

public Object call() throws Exception {

Bar myEntity = new Bar(“Hello world from database!”);


return null;





public void testFindTheBar() throws Exception {

BarDao myEntityDao = new BarDao();

Bar helloEntity = myEntityDao.findTheBar(db);




I didn’t get the source for persistence.xml escaped property, here’s another try after consulting markdown dingus.


I didn’t get the source for persistence.xml escaped property, here’s another try after consulting markdown dingus.



I didn't get the source for persistence.xml escaped property, here's another try.


``` <persistence version="1.0" xmlns="" xmlns:xsi="" xsi:schemaLocation=""> <persistence-unit name="unittest"> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /> <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" /> <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:oc-test-db" /> <property name="" value="create-drop" /> <property name="hibernate.connection.username" value="sa" /> <property name="hibernate.connection.password" value="" /> <property name="hibernate.connection.pool_size" value="7" /> <property name="hibernate.connection.isolation" value="1" /> <property name="hibernate.cache.use_second_level_cache" value="false" /> </properties> </persistence-unit> </persistence> ```

Yet another attempt here to include the source of the xml file.


<persistence version=“1.0” xmlns=“” xmlns:xsi=“” xsi:schemaLocation=“”> <persistence-unit name=“unittest”> <properties> <property name=“hibernate.dialect” value=“org.hibernate.dialect.HSQLDialect” /> <property name=“hibernate.connection.driver_class” value=“org.hsqldb.jdbcDriver” /> <property name=“hibernate.connection.url” value=“jdbc:hsqldb:mem:oc-test-db” /> <property name=“” value=“create-drop” /> <property name=“hibernate.connection.username” value=“sa” /> <property name=“hibernate.connection.password” value="" /> <property name=“hibernate.connection.pool_size” value=“7” /> <property name=“hibernate.connection.isolation” value=“1” /> <property name=“hibernate.cache.use_second_level_cache” value=“false” /> </properties> </persistence-unit> </persistence>


sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir


That does indeed solve my problem. In my case, using a single folder for resource and classes output is just fine. Thank you very much!