Hibernate java.util.ArrayList cannot be cast.. Class cast exception - java

I am trying to read certain values from the hsql db and these values are returned as map with key and value. I have one more method which will accept these map values and will iterate through it and will fetch certain values based on the conditions.After this it will add all these values to a list. for me the condition and the first method is working fine but while adding the values to the list I am facing the class cast exception
Method which reads values from the table:
List<EntityMap> sample = session.createQuery(" FROM EntityMap order by if.ifName").list();
for (Iterator<EntityMap> iterator = sample.iterator(); iterator.hasNext();) {
entityMap = (EntityMap) iterator.next();
if (IfName != entityMap.getIf().getIfName().toString()) {
IfName = entityMap.getIf().getIfName().toString();
entitymapobject = new ArrayList<EntityMap>();
}
entitymapobject.add(entityMap);
EntityMaplist.put(entityMap.getIf().getIfName(),entitymapobject);
}
tx.commit();
This method is returning a map and it has the values which is fetched from the db. After that i am trying to extract certain values based on some conditions.In this I am calling the above method and i am iterating through it
proertyMap = listPROPERTNAMES();
System.out.println("inside loadproperty");
for (Iterator<Integer> itr1 = srcEntityIDList.iterator(); itr1.hasNext();) {
Integer aInteger = itr1.next();
for (Map.Entry<Long, List<PropertyMap>> entry : proertyMap.entrySet()) {
System.out.println(aInteger);
System.out.println(entry.getKey());
Long aLong = entry.getKey();
if (aLong.equals(Long.valueOf(aInteger))) {
System.out.println("values are equal");
trgtPropNameList.add(( (PropertyMap) entry.getValue()).getTgtpropnm());
}
}
}
return trgtPropNameList;
if (tx != null)
tx.rollback();
e.printStackTrace();
} finally {
session.close();
}
return EntityMaplist;
}
Here while trying to add the values to the list (trgtPropNameList) I am getting a class cast exception. My POJO class which has the setter and the getter methods is
public class PropertyMap implements java.io.Serializable {
private PropertyMapId id;
private EntityMap entityMap;
private String tgtpropnm;
private String splitrule;
private String combinerule;
private String createdby;
private Date createdon;
public PropertyMap() {
}
public PropertyMap(PropertyMapId id, EntityMap entityMap) {
this.id = id;
this.entityMap = entityMap;
}
public PropertyMap(PropertyMapId id, EntityMap entityMap, String tgtpropnm,
String splitrule, String combinerule, String createdby,
Date createdon) {
this.id = id;
this.entityMap = entityMap;
this.tgtpropnm = tgtpropnm;
this.splitrule = splitrule;
this.combinerule = combinerule;
this.createdby = createdby;
this.createdon = createdon;
}
public PropertyMapId getId() {
return this.id;
}
public void setId(PropertyMapId id) {
this.id = id;
}
public EntityMap getEntityMap() {
return this.entityMap;
}
public void setEntityMap(EntityMap entityMap) {
this.entityMap = entityMap;
}
public String getTgtpropnm() {
return this.tgtpropnm;
}
public void setTgtpropnm(String tgtpropnm) {
this.tgtpropnm = tgtpropnm;
}
public String getSplitrule() {
return this.splitrule;
}
public void setSplitrule(String splitrule) {
this.splitrule = splitrule;
}
public String getCombinerule() {
return this.combinerule;
}
public void setCombinerule(String combinerule) {
this.combinerule = combinerule;
}
public String getCreatedby() {
return this.createdby;
}
public void setCreatedby(String createdby) {
this.createdby = createdby;
}
public Date getCreatedon() {
return this.createdon;
}
public void setCreatedon(Date createdon) {
this.createdon = createdon;
}
}
Can anyone please help me here?

entry.getValue() is an object of type List<PropertyMap> and not PropertyMap

If you can't cast it just construct and fill a new one.

Change the line
trgtPropNameList.add(( (PropertyMap) entry.getValue()).getTgtpropnm());
to
for(PropertyMap map : entry.getValue(){
trgtPropNameList.add(((PropertyMap)map).getTgtpropnm());
}
Should fix the casting problem.

Related

How to sort the list by fields in Java Spring Boot?

I relatively recently started teaching Spring and programming. I try to sort the list by date, but I can't. I can't come to the right decision. I will be very grateful for your help.
Is request:
> GET http://localhost:8080/expenses
How do I get a response like this:
{
“2021-04-22”: [
{
“id”: 2,
“date”: “2021-04-22”,
“amount”: 12,
“currency”: “USD”,
“product”: “Salmon”
}
],
“2021-04-27”: [
{
“id”: 4,
“date”: “2021-04-27”,
“amount”: 4.75,
“currency”: “EUR”,
“product”: “Beer”
},
{
“id”: 5,
“date”: “2021-04-27”,
“amount”: 25.5,
“currency”: “UAH”,
“product”: “Sweets”
}
]
}
Here is my code:
This is my class of Expense:
public class Expense {
private int id;
private static int idInc = 0;
private double amount;
private String currency;
private String product;
private String date;
public Expense() {
this.id = idInc++;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
This is my controller:
#RestController
public class ExpenseController {
#Autowired
private ExpenseService expenseService;
#RequestMapping("/expenses")
public Map<String, Object> all() {
return expenseService.getAllExpensesList();
}
#RequestMapping(method = RequestMethod.POST, value = "/expenses")
public void addExpense(#RequestBody Expense newExpense) {
expenseService.addExpense(newExpense);
}
}
This is my service:
#Service
public class ExpenseService {
private Map<String, Object> map = new HashMap<>();
public Map<String, Object> getAllExpensesList(){
return map;
}
public void addExpense(Expense expense){
if(!map.containsKey(expense.getDate())) {
List<Expense> al = new ArrayList<>();
al.add(expense);
map.put(expense.getDate(), al);
}
else if(map.containsKey(expense.getDate())){
List<Expense> al = new ArrayList<>();
al.add(expense);
map.put(expense.getDate(), al);
}
}
}
How to do it right?
How to properly sort the list by date?
This has nothing to do with Spring. This is a simple grouping by date string, and sort by date operations you are looking at. Sorting can be achieved by using a TreeMap in which the keys are sorted.
I have not compiled this code, so please bear with me if there are any syntax errors.
Map<String,List<Expense>> resultMap = expenseList.stream().collect(Collectors.groupingBy(Expense::getDate, TreeMap::new, Collectors.toList());
The above code will give you the Map that you are expecting. You'll need to implement Comparable interface for TreeMap to sort the keys for you. Something like,
#Override
public int compareTo(Expense o) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
return sdf.parse(this.date).compareTo(sdf.parse(o.getDate()));
} catch (Exception e) {
System.err.println(e.getMessage()); //Please handle it better!
}
return 0;
}
Your class needs to implement Comparable interface, and You need to #Override the compare method in your class.
That should guide you to the right answer
you should use the Comparable interface and use Date object instead of a string to represent the date.
import java.time.LocalDate;
public class Expense implements Comparable<Expense> {
// all your fields
private LocalDate date; // instead of private String date;
// all getters and setters and constructor
#Override
public int compareTo(Expense e) {
if(this.date.isBefore(e))
return -1;
else if(this.date.isAfter(e))
return 1;
return 0;
}
}
while the date is String you can directly deal with compareTo:
if s1 > s2, it returns positive number
if s1 < s2, it returns negative number
if s1 == s2, it returns 0
and for instance, you can use a custom comparator :
Collections.sort(list, (s1, s2) -> s1.getDate().compareTo(s2.getDate()) > 1 ? 1 : s1.getDate().compareTo(s2.getDate()) < 1 ? -1 : 0);

Removing full object from a value

Helper Class
public class HomeScreenChatsHelper implements Comparable {
private String ID;
private String Name;
private String Image;
private String From;
private String Seen;
private String LastMessage;
private String LastMessageTime;
public HomeScreenChatsHelper(){
}
public HomeScreenChatsHelper(String id, String name, String image, String from, String seen, String lastmessage, String lastMessageTime) {
this.ID=id;
this.Name = name;
this.Image = image;
this.From = from;
this.Seen = seen;
this.LastMessage = lastmessage;
this.LastMessageTime = lastMessageTime;
}
public String getID() {
return ID;
}
public void setID(String id) {
ID = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getImage() {
return Image;
}
public void setImage(String image) {
Image = image;
}
public String getMessage() {
return LastMessage;
}
public void setMessage(String message) {
LastMessage = message;
}
public String getTime() {
return LastMessageTime;
}
public void setTime(String time) {
LastMessageTime = time;
}
public String getFrom() {
return From;
}
public void setFrom(String from) {
From = from;
}
public String getSeen() {
return Seen;
}
public void setSeen(String seen) {
Seen = seen;
}
#RequiresApi(api = Build.VERSION_CODES.KITKAT)
#Override
public int compareTo(Object comparestu) {
long compareage= Long.parseLong(((HomeScreenChatsHelper)comparestu).getTime());
long a = Long.parseLong(LastMessageTime);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
}
return Long.compare(a,compareage);
}
#Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof HomeScreenChatsHelper)) return false;
HomeScreenChatsHelper that = (HomeScreenChatsHelper) o;
return getID().equals(that.getID());
}
#Override
public int hashCode() {
return getID().hashCode();
}
Activity
for(HomeScreenChatsHelper str : mChats) {
if (str.getID().equals(ID)) {
mChats.remove(ID);
break;
}
}
There are a ton of tutorials on how to do it and I've spent the past week looking for a solution and I still don't have it. Is there anyway I can remove an whole object by just specifying just the ID? I wont have the values of all the other fields so I just want to remove a particular object by its ID. Also I cant use the clear option because I need the other data. So can someone help me out please?
With the present code nothing happens. No errors but doesn't work
By using java-8 you can filter the list, result will be the List<HomeScreenChatsHelper> that does have HomeScreenChatsHelper with same id
List<HomeScreenChatsHelper> mChats = new ArrayList<>();
//filter
List<HomeScreenChatsHelper> result = mChats.stream()
.filter(str->!str.getId().equals(Id)).
.collect(Collectors.toList());
Or by using Iterator
// Iterator.remove()
Iterator itr = mChats.iterator();
while (itr.hasNext())
{
HomeScreenChatsHelper x = itr.next();
if (x.getId().equals(Id)) }
itr.remove();
}
}
Your question is quite unclear. is mChats a List containing HomeScreenChatsHelper objects?
I assume so. If this is the case, then you can change your foreach loop into the normal loop
//Assuming mChats is List e.g ArrayList
for (int i = 0; mChats.size(); i++){
if (mChats.get(i).getID().equals(ID)) {
mChats.remove(i);
break;
}
}
The easiest way in Java 8 or later is with Collection#removeIf:
mChats.removeIf(str -> str.getID().equals(ID));
By the way, the convention in Java is for fields to begin with a lowercase letter.

Ljava.lang.Object; cannot be cast to model

in this case, i want to show Json to an response page in java hibernate, query method from DAO like this:
public List<TransactionQR> getAllTransaction() throws HibernateException {
return this.session.createQuery("FROM TransactionQR tr, Batch b, Terminal t, User_Smartphone us, Merchant mc WHERE tr.batch = b.id AND b.user_smartphone = us.id AND b.terminal = t.id AND t.merchant = mc.id AND state = '1' ").list();
}
then in servlet class i try to convert the list into json using Json object and json array then write in response like this:
int start = 0;
String jsonResult = null;
JSONObject jo=new JSONObject();
HttpServletRequest request = context.getRequest();
HttpServletResponse response = context.getResponse();
HttpSession session = context.getSession();
DB db = getDB(context);
//JSONObject jo = new JSONObject();
QRTransactionDao QR = new QRTransactionDao(db);
//Gson objGson = new GsonBuilder().setPrettyPrinting().create();
//String json = objGson.toJson(QR.getAllTransaction());
//System.out.println(json);
List<TransactionQR> str = QR.getAllTransaction();
JSONArray array = new JSONArray();
for(TransactionQR tr : str){
JSONObject str3 = new JSONObject();
str3.put("amount", tr.getAmount());
context.put("jsoncontent", jsonResult);
array.add(str3);
}
jo.put("status", "ok");
jo.put("dataqr", array);
jsonResult=jo.toString();
response.setContentType("application/json");
response.getWriter().print(jsonResult);
but i got the error on syntax in this line loop:
for(TransactionQR tr : str){
the error like this:
[Ljava.lang.Object; cannot be cast to Transaction
here the model Transaction:
package id.co.keriss.consolidate.ee;
import java.io.Serializable;
import java.util.Date;
public class TransactionQR implements Serializable{
private Long id;
private String codeqr;
private Date approvaltime;
private String merchant;
private String code_merchant;
private Long amount;
private Long saldoawal;
private Integer tracenumber;
private String state;
private Date createdate;
private Batch batch;
public TransactionQR() {
}
public TransactionQR(Long id, String codeqr, Date approvaltime, String merchant, String code_merchant, Long amount,
Long saldoawal, Integer tracenumber, String state, Date createdate, Batch batch) {
super();
this.id = id;
this.codeqr = codeqr;
this.approvaltime = approvaltime;
this.merchant = merchant;
this.code_merchant = code_merchant;
this.amount = amount;
this.saldoawal = saldoawal;
this.tracenumber = tracenumber;
this.state = state;
this.createdate = createdate;
this.batch = batch;
}
public Long getId() {
return id;
}
public Date getApprovalTime() {
return approvaltime;
}
public Batch getBatch() {
return batch;
}
public void setBatch(Batch batch) {
this.batch = batch;
}
public void setApprovalTime(Date approvalTime) {
this.approvaltime = approvalTime;
}
public void setId(Long id) {
this.id = id;
}
public Date getApprovaltime() {
return approvaltime;
}
public void setApprovaltime(Date approvaltime) {
this.approvaltime = approvaltime;
}
public String getCodeqr() {
return codeqr;
}
public void setCodeqr(String codeqr) {
this.codeqr = codeqr;
}
public String getMerchant() {
return merchant;
}
public void setMerchant(String merchant) {
this.merchant = merchant;
}
public String getCode_merchant() {
return code_merchant;
}
public void setCode_merchant(String code_merchant) {
this.code_merchant = code_merchant;
}
public Long getAmount() {
return amount;
}
public void setAmount(Long amount) {
this.amount = amount;
}
public Long getSaldoawal() {
return saldoawal;
}
public void setSaldoawal(Long saldoawal) {
this.saldoawal = saldoawal;
}
public Integer getTracenumber() {
return tracenumber;
}
public void setTracenumber(Integer tracenumber) {
this.tracenumber = tracenumber;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Date getCreatedate() {
return createdate;
}
public void setCreatedate(Date createdate) {
this.createdate = createdate;
}
}
i have try to handle the list with Gson:
Gson objGson = new GsonBuilder().setPrettyPrinting().create();
String json = objGson.toJson(QR.getAllTransaction());
System.out.println(json);
in that way, it's work to show but it's not from POJO right i want work with pojo to parse the data to json ?
why i get the error can't cast to model ? any clue ?
Try adding Select tr to your query in getAllTransaction()
Wich is the relation between QRTransactionDao and TransactionQR ?

Room #Insert does not insert all records

I am running into an issue where only 1 record is being inserted into my Room SQLite DB.
When I perform a getAll(); the result only returns 1 record.
FOUND ISSUE: Genre[] genres = gson.fromJson(jsonArray.toString(), Genre[].class);
This line above is setting all "gid" values to 0, and I am not sure how to change that.
Genre.java
#Entity(indices = {#Index(value = {"id", "name"}, unique = true)})
public class Genre {
#PrimaryKey
private int gid;
//#ColumnInfo(name = "id") By Default - No need to annotate
#NonNull
private int id;
private String name;
public int getGid() {
return gid;
}
public void setGid(int gid) {
this.gid = gid;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
GenreDao.java
#Dao
public interface GenreDao {
#Query("SELECT * FROM Genre")
LiveData<List<Genre>> getAll();
#Insert(onConflict = OnConflictStrategy.REPLACE) //If there is a conflict, replace the record.
void insertAll(Genre... genres);
}
GenreRepository.java
public class GenreRepository {
private final GenreDao genreDao;
public GenreRepository(GenreDao genreDao) {
this.genreDao = genreDao;
}
//Database Methods
public void insertAll(Genre... genres) {
AsyncTask.execute(() -> { //Same as new Runnable()
genreDao.insertAll(genres);
});
}
public LiveData<List<Genre>> getAll() {
return genreDao.getAll();
}
}
APIUtil.java - getGenres() Method
This class makes an API call, returns the proper results, converts the JSONArray to a Genre[]. I can successfully loop through the Genre[] and confirm 10+ results come back.
public static void getGenres(Context context) {
APIWrapper wrapper = new APIWrapper(context, API_KEY);
Parameters params = new Parameters();
params.addFields(GENRE_FIELDS);
params.addLimit("50");
wrapper.genres(params, new onSuccessCallback() {
#Override
public void onSuccess(JSONArray jsonArray) {
Gson gson = new Gson();
Genre[] genres = gson.fromJson(jsonArray.toString(), Genre[].class);
//Insert DB
AppDatabase db = AppDatabase.getAppDatabase(context);
GenreRepository genreRepository = new GenreRepository(db.genreDao());
genreRepository.insertAll(genres);
}
#Override
public void onError(VolleyError volleyError) {
Log.e("GENRES ERROR:", volleyError.toString());
}
});
}
GenreViewModel.java
public class GenreViewModel extends ViewModel {
private GenreRepository genreRepository;
public GenreViewModel(GenreRepository genreRepository) {
this.genreRepository = genreRepository;
}
public void insertAll(Genre... genres){
genreRepository.insertAll(genres);
}
public LiveData<List<Genre>> getAll(){
return genreRepository.getAll();
}
}
SearchFragment.java
This is where I am retrieving the database values. This for loop only returns 1 result.
AppDatabase db = AppDatabase.getAppDatabase(getActivity());
GenreRepository genreRepository = new GenreRepository(db.genreDao());
GenreViewModel genreViewModel = new GenreViewModel(genreRepository);
genreViewModel.getAll().observe(this, genres -> { //new Observer<List<Genre>>()
for(Genre g : genres){
Log.e("GENRE", g.getName());
}
});
public void insertAll(Genre... genres){
genreRepository.insertAll(genres);
}
here is your mistake , what you provide as method definition and what you provide at call. see you make some thing wrong.
Solution
void insertAll(List<T> obj);
you can try with convert your array to list and put above in definition
I had this problem too.
And Solved it this way.
The problem was that the id that comes from server was mongoId and String so I should create a int primary key and pass currentTime as value to it so the database can insert all of them not replace them.
But you should consider using System.nanoTime() method instead of System.currentTimeMillis() cause sometimes it generates same value and then room replace them instead of inserting each one of them.

How does Spring Data (MongoDB) read an object?

I am currently working on a project using the Spring framework and SpringData MongoDB (v.1.6.1 RELEASE). I now want to add a property to a stored object, that would simplify its retrieval, but I need to compute this property based on the state of the object at the point of time I want to save it. I tried to put that computation within the getter method of the object, but somehow SpringData is not using the getter to access the property.
The concrete example is the following:
I am storing events in the database and the events are allowed to span over several dates, creating a multi-date event. The events are defined by a start date (LocalDateTime) and an end date (LocalDateTime). I now want to store the information, if the event is a multi-date event or not, within the database. Concluding I added a boolean variable to the event (multiDate). Within the getter (isMultiDate) I am comparing the start and end date and returning true or false (depending on the dates).
My event object:
public class Event
{
#Id
private String id;
#NotBlank
private String name;
private String description;
private String location;
private double locationLat;
private double locationLog;
#NotNull
#JsonIgnore
private int startDateDayOfMonth, startDateMonth, startDateYear, startDateHour, startDateMinute;
#NotNull
#JsonIgnore
private int endDateDayOfMonth, endDateMonth,endDateYear, endDateHour, endDateMinute;
#LastModifiedDate
private Date lastChanged;
#Transient
private LocalDateTime startDateTime;
#Transient
private LocalDateTime endDateTime;
private boolean multiDate;
#DBRef
#NotEmpty
private List<Division> invitedDivision;
public Event() {}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public String getLocation()
{
return location;
}
public void setLocation(String location)
{
this.location = location;
}
public double getLocationLat()
{
return locationLat;
}
public void setLocationLat(double locationLat)
{
this.locationLat = locationLat;
}
public double getLocationLog()
{
return locationLog;
}
public void setLocationLog(double locationLog)
{
this.locationLog = locationLog;
}
public int getStartDateDayOfMonth()
{
return startDateDayOfMonth;
}
public void setStartDateDayOfMonth(int startDateDayOfMonth)
{
this.startDateDayOfMonth = startDateDayOfMonth;
}
public int getStartDateMonth()
{
return startDateMonth;
}
public void setStartDateMonth(int startDateMonth)
{
this.startDateMonth = startDateMonth;
}
public int getStartDateYear()
{
return startDateYear;
}
public void setStartDateYear(int startDateYear)
{
this.startDateYear = startDateYear;
}
public int getStartDateHour()
{
return startDateHour;
}
public void setStartDateHour(int startDateHour)
{
this.startDateHour = startDateHour;
}
public int getStartDateMinute()
{
return startDateMinute;
}
public void setStartDateMinute(int startDateMinute)
{
this.startDateMinute = startDateMinute;
}
public int getEndDateDayOfMonth()
{
return endDateDayOfMonth;
}
public void setEndDateDayOfMonth(int endDateDayOfMonth)
{
this.endDateDayOfMonth = endDateDayOfMonth;
}
public int getEndDateMonth()
{
return endDateMonth;
}
public void setEndDateMonth(int endDateMonth)
{
this.endDateMonth = endDateMonth;
}
public int getEndDateYear()
{
return endDateYear;
}
public void setEndDateYear(int endDateYear)
{
this.endDateYear = endDateYear;
}
public int getEndDateHour()
{
return endDateHour;
}
public void setEndDateHour(int endDateHour)
{
this.endDateHour = endDateHour;
}
public int getEndDateMinute()
{
return endDateMinute;
}
public void setEndDateMinute(int endDateMinute)
{
this.endDateMinute = endDateMinute;
}
public Date getLastChanged()
{
return lastChanged;
}
public void setLastChanged(Date lastChanged)
{
this.lastChanged = lastChanged;
}
public LocalDateTime getStartDateTime()
{
startDateTime = LocalDateTime.of(startDateYear, startDateMonth, startDateDayOfMonth, startDateHour, startDateMinute);
return startDateTime;
}
public void setStartDateTime(LocalDateTime startDateTime)
{
this.startDateTime = startDateTime;
if(startDateTime != null)
{
startDateYear = startDateTime.getYear();
startDateMonth = startDateTime.getMonthValue();
startDateDayOfMonth = startDateTime.getDayOfMonth();
startDateHour = startDateTime.getHour();
startDateMinute = startDateTime.getMinute();
}
}
public LocalDateTime getEndDateTime()
{
endDateTime = LocalDateTime.of(endDateYear, endDateMonth, endDateDayOfMonth, endDateHour, endDateMinute);
return endDateTime;
}
public void setEndDateTime(LocalDateTime endDateTime)
{
this.endDateTime = endDateTime;
if(endDateTime != null)
{
endDateYear = endDateTime.getYear();
endDateMonth = endDateTime.getMonthValue();
endDateDayOfMonth = endDateTime.getDayOfMonth();
endDateHour = endDateTime.getHour();
endDateMinute = endDateTime.getMinute();
}
}
public List<Division> getInvitedDivision()
{
return invitedDivision;
}
/**
* The function is setting all invited divisions, but is optimizing the set by eliminating unnecessary divisions.
* #param invitedDivision
*/
public void setInvitedDivision(List<Division> invitedDivision)
{
if(invitedDivision != null)
{
this.invitedDivision = DivisionManagementController.getOptimizedSetOfDivisions(invitedDivision);
} else
{
this.invitedDivision = invitedDivision;
}
}
public void addDivision(Division division)
{
if(invitedDivision == null)
{
invitedDivision = new ArrayList<>();
}
invitedDivision.add(division);
}
public boolean isMultiDate()
{
return (startDateDayOfMonth != endDateDayOfMonth) || (startDateMonth != endDateMonth) || (startDateYear != endDateYear);
}
public void setMultiDate(boolean multiDate)
{
this.multiDate = multiDate;
}
}
What am I getting wrong? Why is SpringData not using the public getter to access a private variable? (I actually returned always true and the database still only showed storing false).
Thanks in advance!
I am still not clear about the issue, but try this
public boolean isMultiDate()
{
multiDate = (startDateDayOfMonth != endDateDayOfMonth) || (startDateMonth != endDateMonth) || (startDateYear != endDateYear);
return multiDate;
}

Categories