Unable to read Map<String,Object> field from couchbase using spring data couchbase - spring-data

Facing issue while loading document with Map<String,Object> type in my model.
protected Map<String, Object> attributes;
while loading data from couchbase getting Basic type must not be null! error.
is there any way we can load such attributes from couchbase, I am able to store but loading has issue.

protected Map<String, Object> attributes;
It's not possible to construct objects of type Object from data from a document. The second parameter of Map must be an entity or simple type.

Related

Spring Data: query by example using setter accessor

I have a class that contains javafx StringProperty (and SimpleStringProperty).
My MongoRepository correctly stores objects and class types.
Retrieval via query by example throws the following Exception:
java.lang.UnsupportedOperationException: Cannot set immutable property javafx.beans.property.SimpleStringProperty.name!
Can Spring Data and/or MongoRepository be configured to use setter methods, rather than trying to set the property directly?

Map to customized (dynamically generated but with same structure) tables entity framework core

I have dbcontext class let's say.
"tblProp".
On querying I want it to point to "tblProp_1" when I pass 1 as an argument.
Is this type of querying through ef core possible?
There is class method in dbcontext named entity.toTable("tblProp").
Is it possible to use that method to map to what I have described above?
Yes, you can do that provided that these databases share the same schema. You can create a parameterized constructor and pass the parameter whiling creating the DB context.
You can't do it without calling OnModelCreating method which is called once per DbContext type and have the caching functionality.
Following is possible through linq2db.EntityFrameworkCore
var items = context.DbSet<Table>().ToLinqToDBTable().TableName("table_3")
.Where(...)
.ToList();
For sure ChangeTracker will be not availaible but CRUD operation can be performed in other way:
var affected = context.DbSet<Table>().ToLinqToDBTable().TableName("table_3")
.Where(...)
.Set(v => v.Field, someValue)
.Update();
Source

_class field and spring data couchbase

So, I was trying to find a way to remove/rename( and change the fields value ) the _class field from the document generated by spring data couchbase as the document is going to be stored by one service and in all likeliness be consumed by someone totally different.
I was playing around with the api for spring couchbase and through a bit of trial and error found that I can rename the _class field with a custom value using the following way ->
1) Override the typeKey method in a class inheriting AbstractCouchbaseConfiguration . For example, let's say we overrided typeKey to do the following ->
#Override
public String typeKey() {
return "type";
}
2) In the POJO that stores the data into couchbase, add a field with the same field name as what you gave into the return value of the typeKey method and give it the custom value as needed -
private final String type = "studentDoc";
I wanted to check if this is a valid way of going about this or/and some better way is available to do something like this now
That is the only way to do it with spring data at this moment, we would like to add a few extra ways to do that but we are limited to the Spring Data interface contracts. That is why most of the extra configs are done via AbstractCouchbaseConfiguration.
Spring data library needs a field with the fully qualified class name as it's value to understand which class object to deserialize the data from couchbase into. By default, this field would be named _class, but can be modified by overriding the typeKey() method in your Couchbase configuration (extending AbstractCouchbaseConfiguration) as mentioned by you.
#Override
public String typeKey() {
return "customType";
}
But as far as I know, you shouldn't modify the value of the field since the library would not be able to understand which object to deserialize the data into.

Extending Breeze Entities that don't map to database

I am trying to return and extend a type that is defined in my server data model, but is not contained in the EF DataContext. Using breeze, I am able to return it from the BreezeController, but I cannot call registerEntityTypeCtor with the entity type, because the EntityType is not contained within the metadata.
I would like to be able to extend the model (currently just showing in console as type 'Object') with computed properties for display in an Angular app... Think 'fullName'.
Is there a way to do this within Breeze?
You can create and add an EntityType directly to the MetadataStore via the MetadataStore.addEntityType method. See the NoDb sample in the Breeze zip for an example of this.
Once you have the EntityType you can then call 'registerEntityTypeCtor'. If you have 'named' the EntityType consistent with the server side type that will be serialized to the client then Breeze will automatically recognize it. If not then you can either use the EntityQuery.toType method to force a query result to be recognized as being of your new type or more generally you can create a JsonResultsAdapter to do the same thing.

JavaBeans and JasperReports

I'm using JasperReports with JavaBeans (I need to print reports in a application that uses Hibernate). Now I can work out Beans collections and use them in JasperReports, but sometimes I wonder if there is a way to access bean properties without it being a collection. What I mean is that I use JRBeanCollectionSource as a source for the various subReports. Suppose I've a list of People and each of them has a Car property. Now is there a way to access directly car properties without seeing it as a collection?
You could try pulling the property out of the Bean and putting in a different DataSource like for example JRMapCollectionDataSource.
This would mean not having to deal with the whole Bean collection each time.
Here is some sample code for constructing a DataSource.
Collection<Map<String, Object>> myColl = new ArrayList<Map<String,Object>>();
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("Field1","Value1");
map1.put("Field2","Value2");
map1.put("Field3", someObject);
myColl.add(map1);
JRMapCollectionDataSource source = new JRMapCollectionDataSource(myColl);