roy_sanu
asked on
Concern with JPA issue
while defining a Base Model of teh database is it necessary to define
is this correct to define <String ,Object> or any other way so that future it may not trouble in the code.Let us me know expert as this is important we are doing a college project
private Map<String, Object> objectMap = new HashMap<String, Object>();
is this correct to define <String ,Object> or any other way so that future it may not trouble in the code.Let us me know expert as this is important we are doing a college project
@JsonSerialize(using = DefaultSerializer.class)}
@MappedSuperclass
public abstract class BaseModel extends Convertable {
@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationT ype.IDENTI TY)
private int id;
// dis is used to create teh Json view of current object
@Transient
private Map<String, Object> objectMap = new HashMap<String, Object>();
public Map<String, Object> getObjectMap() {
return objectMap;
}
public int getId() {
return id;
}
@Column(updatable = false)
@CreationTimestamp
private LocalDateTime created = LocalDateTime.now();
@UpdateTimestamp
private LocalDateTime lastModified;
public LocalDateTime getCreated() {
return created;
}
public void setCreated(LocalDateTime date) {
created = date;
}
public LocalDateTime getLastModified() {
return lastModified;
}
@Override
public void buildObjectMap() {
objectMap.put("id", String.valueOf(id));
}
@Override
public String toJSONString() {
buildObjectMap();
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
return gson.toJson(objectMap, Map.class);
}
@Override
public Map<String, Object> toJsonizedMap() {
buildObjectMap();
return objectMap;
}
better you can create POJO class and use of instant of object
ASKER
Satish Expert,
I like know if do in pojo what changes I should make this class as we want data should data with two database and we want data is in json as of now.if you can create some class skeleton let us know.Another way is working on database is easy for me but using jpa based relationship is bit difficult for me.if you better way represent let me know.by the way Cassandra non sql database is being used so what i feel object should object i guess, is it possible to use object calling string in the future so that load on Cassandra database would be less.
I like know if do in pojo what changes I should make this class as we want data should data with two database and we want data is in json as of now.if you can create some class skeleton let us know.Another way is working on database is easy for me but using jpa based relationship is bit difficult for me.if you better way represent let me know.by the way Cassandra non sql database is being used so what i feel object should object i guess, is it possible to use object calling string in the future so that load on Cassandra database would be less.
ASKER
What I mean calling objects should be calling object as a mapper, As you are an architect if you can put some light on if object needs to be shared by other database will it be a problem in the future or not. Calling object in a class but calling a class from a object may not be right.
Thanx expert Satish sir.any update let us know
Daisy Roy.
Thanx expert Satish sir.any update let us know
Daisy Roy.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.