Is there a SpringData Mongo equivalent of the JPA #Column annotation?
Basically, I've got a POJO with a property that I want to store in Mongo with a different name. So, the following object:
public class Pojo{
#Property("bar")
private String foo = "Hello World";
}
would be persisted as:
{
"_class":"com.example.Pojo",
"bar" : "Hello World"
}
Note: I don't want to use the MappingMongoConverter to explicitly do it
The Spring Data reference documentation lists #Field as the annotation to customize the key and ordering of properties mapped to a MongoDB document.
You can use #Field
It lets you define custom key name in DB and the insert order
Related
Using the influxdb library in Java I'm trying to map the results of a query formed using the QueryReactiveAPI query builder to a POJO so I can store them for processing. I get that you need to use the #Measurement annotation on the class definition and the #Column annotation on class variables to map fields but is there the equivalent for tags?
Thanks.
You can also use the #Column annotation for tags, simply include tag = true in the annotation, for example:
#Column(tag = true)
String location;
Source: https://github.com/influxdata/influxdb-client-java#writes-and-queries-in-influxdb-2x
I am new to Marklogic and want to specify collection name externally in Java POJO. Currently spring JPA repository tries to search for collection with name as class name of pojo.
#Repository
public interface PersonRepository extends MarkLogicRepository<Person, String> {
}
public class Person {
#Id
private String personId;
private String personName;
}
So in above example, spring fetched data from "Person" collection which is fine for my local development. But for Dev and Test servers, I need to fetch data from versioned collection like "Person_V1"/ "Person_V2" which can be configured in application.properties file.
How can I make collection name configurable?
It is worth noting that MarkLogic collection is one of the document metadata categories. It is non-hierarchical and version|class-independent.
Seems to me you first attempt to map entity POJO to define collection which requires marshalling. The Annotation will be something like:
#Document(
uri = "/person_{version}/${GUID}.xml",
collectionPrefix = "{collection-prefix|null}",
collection = "${method.getName()}"
)
2ndly, you said you wish to cconfigure the collection in application.properties. Then the .properties file looks like this:
# prefix could be `Person_V1`, ` Person_V2` or null
person.collectionPrefix =
person.collection =
You can define the Annotation in the main class like:
#Value("${person.collectionPrefix}")
private String ***;
#Value("${person.collection}")
private String ***;
The optimised MarkLogic Java document operation boils down to:
metadata(Handle).getCollections().add(All)("{collection-array}");
What gives you the leeway, though, is to define POJO object as args in method to setCollections() | getCollections().
A full review of MarkLogic metadata Class and Method is:
https://docs.marklogic.com/javadoc/client/com/marklogic/client/io/DocumentMetadataHandle.html
I would like Hibernate to disable certain classes from being validated on startup.
My particular use-case:
spring.jpa.hibernate.ddl-auto=validate
#Table (name = "SAME_TABLE")
public class Entity1 {
#Column
private Long value;
// rest of values
}
#Table (name = "SAME_TABLE")
public class SearchEntity2 {
#Column
private String value;
// rest of values
}
As you can see I have two classes mapped to the same table called SAME_TABLE. This is because I want to do wildcard searches on numeric field value
JPA Validation fails on Oracle (h2 succeeds suprisingly) because it detects that the String is not NUMERIC(10).
This question here by #b0gusb provides an excellent way of filtering out via table name:
How to disable schema validation in Hibernate for certain entities?
Unfortunately my table name is identical. Is there any way of getting to the Java class name from SchemaFilteror perhaps another way of doing this?
Thanks
X
I want to modify the Example Value under the Data Type on my Swagger-ui interface. currently it contains the following default value (generated by Swagger):
"user":{
"birth":null,
"nationality":null,
"lastname":null,
"firstname":null,
"identity":null
}
I want to specify real values instead of the "null" values.
PS: I use spring boot with annotations: #ApiOperation,...
You must then insert #ApiModelProperty anotation for all your attributes inside your bean. Then put an example attribute inside. Let's say your user is mapped to the User.java class, so you would have:
public class User {
#ApiModelProperty(value = "The birthdate", example = "1985-12-07", format= "yyyy-MM-dd")
private String birth;
So I'm trying to use Spring Data with mongodb without providing a strict schema, I have let's say document 'person':
{
'_id':'1234',
'name':'John Doe',
'address':'Texas'
}
So I created a java bean:
#Document(collection='people')
class Person {
#Id
private String id;
private String name;
private String address;
//all getters and setters
}
But on the same hierarchy level in a document I could have different dynamic fields like: hobbies, friends etc.
How can I create a java bean document object to access those dynamic fields in a hash-like manner while using MongoRepository support?
You will need to Override default mapping with custom converters and do the Saving using a registered Spring Converter and Reading using a Spring Converter as described in documentation here