cancel
Showing results for 
Search instead for 
Did you mean: 

Can I set @cds.persistence.exists false for sqlite i.e. for development

NitinMahajan
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

I am trying use CAP to create Odata services on an existing database in HANA cloud. Since the tables exist my model has been created with annotation @cds.persistence.exists on entities.

However, since I want to test the solution in development (via sqlite), is it possible to generate the tables in SQLite only i.e. in development? Otherwise I am not able to test the application in development and have to deploy it always.

Regards,

Nitin

Accepted Solutions (0)

Answers (2)

Answers (2)

lothar_bender
Advisor
Advisor

You can move the HANA specific @cds.persistence.exists annotations into a separate folder. This is best practise in general if you need to distinguish database specific functionality, e.g. SAP HANA functions.

In order to avoid redundant model definitions, create a separate file db/hana/index.cds containing all @cds.persistence.exists annotations, e.g.:

using { namespace } from '../foo'; 
annotate namespace.FOO1 with @cds.persistence.exists;
annotate namespace.FOO2 with @cds.persistence.exists;

Add the following to the cds configuration to your project:

"requires": {   
  "db-ext": {     
    "[production]" : { "model": "db/hana" }
  }
}

cds watch will create the corresponding tables in the sqlite database as the development profile is used while cds build --production will not create the .hdbtable artifacts as the model folder db/hana is added to the list of compiled models setting the annotations for the corresponding entities.

For further details see https://github.com/SAP-samples/cloud-cap-samples/blob/main/fiori/package.json#L41. There is also a CodeTour (Database Functions Step8) for VSCode you can follow.

Regards,
Lothar

florine0113
Explorer
0 Kudos

Hi Lothar,

Thank you for your answer, it really helps.

I understand the ext concept, but do you know how and where can we maintain the db-ext for Java CAP?

Regards,

Florine

NitinMahajan
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Lothar,

How do you tell the service i.e. service.cds which path to pick the model from? /db/sqlite or /db/hana

It is not clear from the samples as well.

Regards,

Nitin