Impetus / kundera

A JPA 2.1 compliant Polyglot Object-Datastore Mapping Library for NoSQL Datastores.Please subscribe to:
http://groups.google.com/group/kundera-discuss/subscribe
Apache License 2.0
903 stars 233 forks source link

"invalid constant type: 18" with java 8 #935

Closed a-polito closed 7 years ago

a-polito commented 7 years ago

Hi,

I'm having the following exception while running Kundera inside a java 8 class. java.io.IOException: invalid constant type: 18 at javassist.bytecode.ConstPool.readOne(ConstPool.java:1090) at javassist.bytecode.ConstPool.read(ConstPool.java:1033) at javassist.bytecode.ConstPool.<init>(ConstPool.java:149) at javassist.bytecode.ClassFile.read(ClassFile.java:737) at javassist.bytecode.ClassFile.<init>(ClassFile.java:108) at com.impetus.kundera.configure.MetamodelConfiguration.scanClassAndPutMetadata(MetamodelConfiguration.java:315) at com.impetus.kundera.configure.MetamodelConfiguration.loadEntityMetadata(MetamodelConfiguration.java:231) at com.impetus.kundera.configure.MetamodelConfiguration.configure(MetamodelConfiguration.java:112) at com.impetus.kundera.persistence.EntityManagerFactoryImpl.configure(EntityManagerFactoryImpl.java:158) at com.impetus.kundera.persistence.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:135) at com.impetus.kundera.KunderaPersistence.createEntityManagerFactory(KunderaPersistence.java:85) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)

The problem is due the fact that Kundera refers to an old version of javassist (3.12.1.GA) that it's not compliant to java 8 bytecode. From the version 3.18.0 this issue has been resolved.

The code I'm using is pretty simple: there are 2 entities with some properties(TaskInstance and JobInstance) and a test class. I'm writing a simple test that inserts one row of TaskInstance and 10 rows of JobInstance. I'm using cassandra as storage. If I run the following code it breaks with the above exception, while replacing the java 8 specific part with the for loop the code completes without errors.

    @Test
    public void createTaskAndJobs() {
        TaskInstance task = newTaskInstance(), result;
        TaskInstanceId id = task.getTaskId();
        em.persist(task);

        result = em.find(TaskInstance.class, new TaskInstanceId(id.getTenant(), id.getRequester(), id.getInsertTs(), id.getTaskId()));
        Assert.assertEquals(Status.NEW, result.getStatus());
/*
        for(int i = 0; i < 10; i++) {
            JobInstance job = newJobInstance(id.getTaskId(), new Random().nextInt(100));
            em.persist(job);
        }
*/
        IntStream.range(0, 10)
                .mapToObj(i -> newJobInstance(id.getTaskId(), new Random().nextInt(100)))
                .forEach(job -> em.persist(job));

        task.setStatus(Status.RUNNING);
        em.merge(task);

        em = emf.createEntityManager();
        result = em.find(TaskInstance.class, new TaskInstanceId(id.getTenant(), id.getRequester(), id.getInsertTs(), id.getTaskId()));
        Assert.assertEquals(task.getTaskId().getTaskId(), result.getTaskId().getTaskId());
        Assert.assertEquals(Status.RUNNING, result.getStatus());
        Assert.assertEquals(new Integer(11), result.getTotalJobs());

        em.close();
        emf.close();
    }

At the moment this pom dependency configuration fixes the issue, but I think it should be fixed on Kundera's dependency tree

    <dependencies>
        <dependency>
            <groupId>com.impetus.kundera.client</groupId>
            <artifactId>kundera-cassandra</artifactId>
            <version>3.8</version>
            <exclusions>
                <exclusion>
                    <groupId>javassist</groupId>
                    <artifactId>javassist</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.20.0-GA</version>
        </dependency>
    </dependencies>

Thank you Andrea

karthikprasad13 commented 7 years ago

@a-polito

Hey Andrea,

We will verify the code with new dependency and change it in the next release.

-Karthik