question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DynamoDB Enhanced v. 2.15.41 putItem - getItem generates java.lang.NoClassDefFoundError

See original GitHub issue

When using DynamoDB version 2.15.41, but even the older versions, with the play framewok 2.8 (java) it throws a NoClassDefFoundError when you set the Table Schema via annotated class or via bean.

Describe the bug

I’m trying to create a simple registration/login application with the support of DynamoDB and Play Framework with java. I downloaded the last play java seed from the official site and added the dependencies for DynamoDb and DynamoDB enhanced v. 2.15.41.

I wrote some simple API’s to call Create - Put - Get for the items. But I’m not able to put or get items from the table

What I mean is that if I define a table as following it will throw a NoClassDefFound when used:

DynamoDbAsyncClient dynamoDbAsyncClient = DynamoDbAsyncClient
    .builder()
    .endpointOverride(URI.create("http://localhost:8000"))
    .build();

DynamoDbEnhancedAsyncClient enhancedAsyncClient = DynamoDbEnhancedAsyncClient
    .builder()
    .dynamoDbClient(dynamoDbAsyncClient)
    .build();

return enhancedAsyncClient.table("Customer", TableSchema.fromClass(Customer.class));
 @DynamoDbBean
    public static class Customer {

        private String  id;
        private String  name;
        private String  email;
        private Instant regDate;

        @DynamoDbPartitionKey
        public String getId() { return this.id; }
        @DynamoDbSortKey
        public String getCustName() { return this.name; }
        //Omitted the getters and setters for brevity
    }

Expected Behavior

I should be able to put and get items correctly.

Current Behavior

When you run this code it’s going to throw the exception.

  Key key = Key.builder()
                .partitionValue("id103")
                .sortValue("Susan Blue")
                .build();

        // Get the item by using the key
        return table.getItem(r -> r.key(key))
ERROR akka.actor.ActorSystemImpl akka.actor.ActorSystemImpl(application) Uncaught error from thread [application-akka.actor.default-dispatcher-6]: controllers/HomeController$Customer, shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[application]
java.lang.NoClassDefFoundError: controllers/HomeController$Customer
	at software.amazon.awssdk.enhanced.dynamodb.internal.mapper.ResolvedImmutableAttribute.lambda$create$0(ResolvedImmutableAttribute.java:48)
	at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.lambda$itemToMap$5(StaticImmutableTableSchema.java:491)
	at java.util.ArrayList.forEach(ArrayList.java:1259)
	at java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1082)
	at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.itemToMap(StaticImmutableTableSchema.java:489)
	at software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema.itemToMap(WrappedTableSchema.java:59)
	at software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema.itemToMap(WrappedTableSchema.java:59)
	at software.amazon.awssdk.enhanced.dynamodb.internal.operations.PutItemOperation.generateRequest(PutItemOperation.java:71)
	at software.amazon.awssdk.enhanced.dynamodb.internal.operations.PutItemOperation.generateRequest(PutItemOperation.java:40)
	at software.amazon.awssdk.enhanced.dynamodb.internal.operations.CommonOperation.executeAsync(CommonOperation.java:139)
	at software.amazon.awssdk.enhanced.dynamodb.internal.operations.TableOperation.executeOnPrimaryIndexAsync(TableOperation.java:81)
	at software.amazon.awssdk.enhanced.dynamodb.internal.client.DefaultDynamoDbAsyncTable.putItem(DefaultDynamoDbAsyncTable.java:177)
	at software.amazon.awssdk.enhanced.dynamodb.internal.client.DefaultDynamoDbAsyncTable.putItem(DefaultDynamoDbAsyncTable.java:185)
	at software.amazon.awssdk.enhanced.dynamodb.internal.client.DefaultDynamoDbAsyncTable.putItem(DefaultDynamoDbAsyncTable.java:190)
	at controllers.HomeController.putItem(HomeController.java:92)
	at router.Routes$$anonfun$routes$1.$anonfun$applyOrElse$8(Routes.scala:169)
	at play.core.routing.HandlerInvokerFactory$$anon$7.resultCall(HandlerInvoker.scala:146)
	at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$3$$anon$4$$anon$5.invocation(HandlerInvoker.scala:115)
	at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:119)
	at play.http.DefaultActionCreator$1.call(DefaultActionCreator.java:33)
	at play.core.j.JavaAction.$anonfun$apply$8(JavaAction.scala:175)
	at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:671)
	at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:430)
	at play.core.j.HttpExecutionContext.$anonfun$execute$1(HttpExecutionContext.scala:64)
	at play.api.libs.streams.Execution$trampoline$.execute(Execution.scala:70)
	at play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:59)
	at scala.concurrent.impl.Promise$Transformation.submitWithValue(Promise.scala:392)
	at scala.concurrent.impl.Promise$DefaultPromise.submitWithValue(Promise.scala:302)
	at scala.concurrent.impl.Promise$DefaultPromise.dispatchOrAddCallbacks(Promise.scala:276)
	at scala.concurrent.impl.Promise$DefaultPromise.map(Promise.scala:146)
	at scala.concurrent.Future$.apply(Future.scala:671)
	at play.core.j.JavaAction.apply(JavaAction.scala:176)
	at play.api.mvc.Action.$anonfun$apply$4(Action.scala:82)
	at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$4(Accumulator.scala:168)
	at scala.util.Try$.apply(Try.scala:210)
	at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$3(Accumulator.scala:168)
	at scala.Function1.$anonfun$andThen$1(Function1.scala:85)
	at scala.Function1.$anonfun$andThen$1(Function1.scala:85)
	at scala.Function1.$anonfun$andThen$1(Function1.scala:85)
	at play.api.libs.streams.StrictAccumulator.run(Accumulator.scala:199)
	at play.core.server.AkkaHttpServer.$anonfun$runAction$4(AkkaHttpServer.scala:417)
	at akka.http.scaladsl.util.FastFuture$.strictTransform$1(FastFuture.scala:41)
	at akka.http.scaladsl.util.FastFuture$.$anonfun$transformWith$3(FastFuture.scala:51)
	at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:447)
	at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:56)
	at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:93)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
	at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:93)
	at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:48)
	at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:48)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)
Caused by: java.lang.ClassNotFoundException: controllers.HomeController$Customer
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 55 common frames omitted

Steps to Reproduce

A public repository with the code could be found here: https://github.com/Max161/AWS_DynamoDB_ClassNotFound_Error

To run the code use sbt run command in the main folder. Than you can use postman to call the API: /createtable /getItem /putItem

Your Environment

  • AWS Java SDK version used: 2.15.41
  • JDK version used: Java 1.8.0_275
  • Operating System and version: Ubuntu 16.04 LTS - Mac Big Sur v 11.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rohit-gandhecommented, Dec 3, 2021

It’s been a year and it’s still an issue 😦

1reaction
u6f6ocommented, Feb 24, 2021

Thx for providing a workaround @Max161. I must admit though, that it feels rather awkward to provide a separate jar for the models.

I hope this will be fixed soon 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

DynamoDB Enhanced v. 2.15.41 putItem - getItem generates java ...
When using DynamoDB version 2.15.41, but even the older versions, with the play framewok 2.8 (java) it throws a NoClassDefFoundError when you set...
Read more >
Using the DynamoDB Enhanced Client in the AWS SDK for ...
The DynamoDB enhanced client is a high-level library that is part of the AWS SDK for Java version 2 (v2). It offers a...
Read more >
DynamoDB Enhanced Client for Java: Missing Setters Cause ...
The AWS SDK v2 for Java's DynamoDB Enhanced Client requires setters for every attribute. Missing the setter for a given attribute may cause ......
Read more >
AWS JAVA dynamoDB enhanced client putItem class cast ...
I'm getting the same issue with aws sdk version 2.16.45. Did you ever figure this out? – Wan Li. May 7, 2021 at...
Read more >
DynamoDbTable (AWS SDK for Java - 2.18.38)
declaration: package: software.amazon.awssdk.enhanced.dynamodb, ... Creates a new table in DynamoDb with the name and schema already defined for this ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found