Skip to main content

Inserting an Object

Here is standard Java code that uses Java Projections to create a new PERSON record and store it in Caché. In detail, the code does the following:

  1. Uses the Java projection constructor to create a new projection, PERSON, instance. This simultaneously creates a new instance of MVFILE.PERSON in Caché. Note that the constructor takes an open CacheDatabase instance as an argument.

  2. Uses the Java projection's setter methods to assign values to its properties. A Java projection contains a setter for each of the public properties of the corresponding Caché class.

  3. Uses the Java projection's save method to save the corresponding Caché object.

PERSON person = new PERSON(db);
List<String> phoneList = person.getPhone();

Please note that the above code sets the ItemId to 10 before saving. This value must be unique in the database. If your database already has an MVFILE.PERSON record with ItemId value 10, please adjust the value in the sample code accordingly.


The above code is contained in This file is in <cachesys>\Dev\tutorials\mv. Executing the Java Examples contains step-by-step instructions for executing this code.

FeedbackOpens in a new tab