cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP Java Insert CQL Statement Error for Denormalized Views

SilasL
Explorer

Dear Experts,

I'm having the following error when I try to execute an insert CQL statement in SAP CAP for Java for a denormalized view, a projection of a database with filters.

Caused by: org.h2.jdbc.JdbcSQLFeatureNotSupportedException: Feature not supported: "TableView.addRow"; SQL statement:

My logic for the insert CQL is below. I have a persistenceservice db attribute for the service.

Inside my eventhandler function, I create a HashMap cart for my Entity Carts. I add an element for the string field "owner" with value "Test" to the HashMap. Then I try to execute the statement to add HashMap cart to the table CARTS.

 

private final PersistenceService db;

Map<String, Object> cart = new HashMap<>();
cart.put("owner", "Test");
db.run(Insert.into(CARTS).entry(cart));

 

Is the error due to how I declared the entity? This is how I've declared my entity in the service.

 

entity Carts as projection on my.Carts where Carts.owner = $user.id;

 

EDIT: I've figured out exactly what changes I need to make to allow the service to create data and changes the title and context. My service can create data either from https request or Insert CQL statement when I remove the where clause in the projection statement in the service. But I want the where condition so that the user can only see their cart.

 

My new question after figuring this out, what's the best practice for adding new entries to a denormalized view in SAP CAP? In my example, I would have users who can shop for items and when they want to add an item. I would first check if their have an existing cart, and if not, create a new cart for them, otherwise add the item to their existing cart.

 

I think I've seen an example where the end user service creates an instances of admin service, where the admin service would create the data since it has full access to the databases. I'm not sure if this is the only way or are there different approaches.

 

Thanks,

Silas

Accepted Solutions (0)

Answers (0)