Collector not finding field - eclipse

I am trying to use a lambda to average a field over another grouped field. It fails and says it can't find field price. It does find the tradeMinutes field without problem. This would lead me to believe that it does now the correct class.
Compilation error in eclipse
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
price cannot be resolved or is not a field
at com.simplegrowth.assets.AssetAdder.<init>(AssetAdder.java:60)
at com.simplegrowth.Reader.<clinit>(Reader.java:23)
groupList function
List<Asset> assetsList = null;
assetsList = assets.get("BILL");
assetsList.stream()
.collect(Collectors.groupingBy( a -> a.tradeMinutesSinceMidnight, Collectors.averagingDouble( a -> a.price) ) )
.forEach(( tradeMinutesSinceMidnight, sumPrice) -> System.out.println(tradeMinutesSinceMidnight + " " + sumPrice));
The asset class
public class Asset implements Serializable, Comparable<Asset> {
private static final long serialVersionUID = 1L;
#Id #GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id; // still set automatically
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
long sequenceNo;
String Exchange;
String Board;
long time;
String paper;
long tradeTime;
long quantity;
double price;
String source;
String buyer;
String seller;
float changeSinceLast;
String initator;
long tradeTimeSinceMidnight;
long tradeMinutesSinceMidnight;
long daysSinceEpoch;
public long getSequenceNo() {
return sequenceNo;
}
public void setSequenceNo(long sequenceNo) {
this.sequenceNo = sequenceNo;
}
public String getExchange() {
return Exchange;
}
public void setExchange(String exchange) {
Exchange = exchange;
}
public String getBoard() {
return Board;
}
public void setBoard(String board) {
Board = board;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public String getPaper() {
return paper;
}
public void setPaper(String paper) {
this.paper = paper;
}
public long getTradeTime() {
return tradeTime;
}
public void setTradeTime(long tradeTime) {
this.tradeTime = tradeTime;
}
public long getQuantity() {
return quantity;
}
public void setQuantity(long quantity) {
this.quantity = quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getBuyer() {
return buyer;
}
public void setBuyer(String buyer) {
this.buyer = buyer;
}
public String getSeller() {
return seller;
}
public void setSeller(String seller) {
this.seller = seller;
}
public float getChangeSinceLast() {
return changeSinceLast;
}
public void setChangeSinceLast(float changeSinceLast) {
this.changeSinceLast = changeSinceLast;
}
public String getInitator() {
return initator;
}
public void setInitator(String initator) {
this.initator = initator;
}
public long getDaysSinceEpoch() {
return daysSinceEpoch;
}
public void setDaysSinceEpoch(long daysSinceEpoch) {
this.daysSinceEpoch = daysSinceEpoch;
}
public long getTradeTimeSinceMidnight() {
return tradeTimeSinceMidnight;
}
public void setTradeTimeSinceMidnight(long tradeTimeSinceMidnight) {
this.tradeTimeSinceMidnight = tradeTimeSinceMidnight;
}
public long getTradeMinutesSinceMidnight() {
return tradeMinutesSinceMidnight;
}
public void setTradeMinutesSinceMidnight(long tradeMinutesSinceMidnight) {
this.tradeMinutesSinceMidnight = tradeMinutesSinceMidnight;
}
#Override
public boolean equals(Object obj) {
if (sequenceNo == ((Asset)obj).sequenceNo)
return true;
return false;
//return super.equals(obj);
}
#Override
public int compareTo(Asset otherAsset) {
if (this.getSequenceNo() < otherAsset.getSequenceNo()) {
return -1;
}
return 1;
}
}

Related

Java Backend sending properties not retrieved by the typescript frontend

I don't understand why in my http Get Call, a properties is send by the backend but not receive in the frontend.
I have this class :
/**
* A Saison.
*/
#Entity
#Table(name = "saison")
#Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Saison implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
#SequenceGenerator(name = "sequenceGenerator")
private Long id;
#NotNull
#Pattern(regexp = "^2[0-9]{3}$")
#Column(name = "annee_saison", nullable = false, unique = true)
private String anneeSaison;
#Column(name = "est_active_saison")
private Boolean estActiveSaison;
#Column(name = "param_jour_lundi")
private Boolean paramJourLundi;
#Column(name = "param_jour_mardi")
private Boolean paramJourMardi;
#Column(name = "param_jour_mercredi")
private Boolean paramJourMercredi;
#Column(name = "param_jour_jeudi")
private Boolean paramJourJeudi;
#Column(name = "param_jour_vendredi")
private Boolean paramJourVendredi;
#Column(name = "param_jour_samedi")
private Boolean paramJourSamedi;
#Column(name = "param_jour_dimanche")
private Boolean paramJourDimanche;
#Column(name = "param_mois_janvier")
private Boolean paramMoisJanvier;
#Column(name = "param_mois_fevrier")
private Boolean paramMoisFevrier;
#Column(name = "param_mois_mars")
private Boolean paramMoisMars;
#Column(name = "param_mois_avril")
private Boolean paramMoisAvril;
#Column(name = "param_mois_mai")
private Boolean paramMoisMai;
#Column(name = "param_mois_juin")
private Boolean paramMoisJuin;
#Column(name = "param_mois_juillet")
private Boolean paramMoisJuillet;
#Column(name = "param_mois_aout")
private Boolean paramMoisAout;
#Column(name = "param_mois_septembre")
private Boolean paramMoisSeptembre;
#Column(name = "param_mois_octobre")
private Boolean paramMoisOctobre;
#Column(name = "param_mois_novembre")
private Boolean paramMoisNovembre;
#Column(name = "param_mois_decembre")
private Boolean paramMoisDecembre;
#OneToMany(mappedBy = "saison")
#Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
#JsonIgnoreProperties(value = { "saison" }, allowSetters = true)
private Set<Seance> seances = new HashSet<>();
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Saison id(Long id) {
this.id = id;
return this;
}
public String getAnneeSaison() {
return this.anneeSaison;
}
public Saison anneeSaison(String anneeSaison) {
this.anneeSaison = anneeSaison;
return this;
}
public void setAnneeSaison(String anneeSaison) {
this.anneeSaison = anneeSaison;
}
public Boolean getEstActiveSaison() {
return this.estActiveSaison;
}
public Saison estActiveSaison(Boolean estActiveSaison) {
this.estActiveSaison = estActiveSaison;
return this;
}
public void setEstActiveSaison(Boolean estActiveSaison) {
this.estActiveSaison = estActiveSaison;
}
public Boolean getParamJourLundi() {
return paramJourLundi;
}
public void setParamJourLundi(Boolean paramJourLundi) {
this.paramJourLundi = paramJourLundi;
}
public Boolean getParamJourMardi() {
return paramJourMardi;
}
public void setParamJourMardi(Boolean paramJourMardi) {
this.paramJourMardi = paramJourMardi;
}
public Boolean getParamJourMercredi() {
return paramJourMercredi;
}
public void setParamJourMercredi(Boolean paramJourMercredi) {
this.paramJourMercredi = paramJourMercredi;
}
public Boolean getParamJourJeudi() {
return paramJourJeudi;
}
public void setParamJourJeudi(Boolean paramJourJeudi) {
this.paramJourJeudi = paramJourJeudi;
}
public Boolean getParamJourVendredi() {
return paramJourVendredi;
}
public void setParamJourVendredi(Boolean paramJourVendredi) {
this.paramJourVendredi = paramJourVendredi;
}
public Boolean getParamJourSamedi() {
return paramJourSamedi;
}
public void setParamJourSamedi(Boolean paramJourSamedi) {
this.paramJourSamedi = paramJourSamedi;
}
public Boolean getParamJourDimanche() {
return paramJourDimanche;
}
public void setParamJourDimanche(Boolean paramJourDimanche) {
this.paramJourDimanche = paramJourDimanche;
}
public Boolean getParamMoisJanvier() {
return paramMoisJanvier;
}
public void setParamMoisJanvier(Boolean paramMoisJanvier) {
this.paramMoisJanvier = paramMoisJanvier;
}
public Boolean getParamMoisFevrier() {
return paramMoisFevrier;
}
public void setParamMoisFevrier(Boolean paramMoisFevrier) {
this.paramMoisFevrier = paramMoisFevrier;
}
public Boolean getParamMoisMars() {
return paramMoisMars;
}
public void setParamMoisMars(Boolean paramMoisMars) {
this.paramMoisMars = paramMoisMars;
}
public Boolean getParamMoisAvril() {
return paramMoisAvril;
}
public void setParamMoisAvril(Boolean paramMoisAvril) {
this.paramMoisAvril = paramMoisAvril;
}
public Boolean getParamMoisMai() {
return paramMoisMai;
}
public void setParamMoisMai(Boolean paramMoisMai) {
this.paramMoisMai = paramMoisMai;
}
public Boolean getParamMoisJuin() {
return paramMoisJuin;
}
public void setParamMoisJuin(Boolean paramMoisJuin) {
this.paramMoisJuin = paramMoisJuin;
}
public Boolean getParamMoisJuillet() {
return paramMoisJuillet;
}
public void setParamMoisJuillet(Boolean paramMoisJuillet) {
this.paramMoisJuillet = paramMoisJuillet;
}
public Boolean getParamMoisAout() {
return paramMoisAout;
}
public void setParamMoisAout(Boolean paramMoisAout) {
this.paramMoisAout = paramMoisAout;
}
public Boolean getParamMoisSeptembre() {
return paramMoisSeptembre;
}
public void setParamMoisSeptembre(Boolean paramMoisSeptembre) {
this.paramMoisSeptembre = paramMoisSeptembre;
}
public Boolean getParamMoisOctobre() {
return paramMoisOctobre;
}
public void setParamMoisOctobre(Boolean paramMoisOctobre) {
this.paramMoisOctobre = paramMoisOctobre;
}
public Boolean getParamMoisNovembre() {
return paramMoisNovembre;
}
public void setParamMoisNovembre(Boolean paramMoisNovembre) {
this.paramMoisNovembre = paramMoisNovembre;
}
public Boolean getParamMoisDecembre() {
return paramMoisDecembre;
}
public void setParamMoisDecembre(Boolean paramMoisDecembre) {
this.paramMoisDecembre = paramMoisDecembre;
}
public Set<Seance> getSeances() {
return this.seances;
}
public Saison seances(Set<Seance> seances) {
this.setSeances(seances);
return this;
}
public Saison addSeance(Seance seance) {
this.seances.add(seance);
seance.setSaison(this);
return this;
}
public Saison removeSeance(Seance seance) {
this.seances.remove(seance);
seance.setSaison(null);
return this;
}
public void setSeances(Set<Seance> seances) {
if (this.seances != null) {
this.seances.forEach(i -> i.setSaison(null));
}
if (seances != null) {
seances.forEach(i -> i.setSaison(this));
}
this.seances = seances;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
#Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Saison)) {
return false;
}
return id != null && id.equals(((Saison) o).id);
}
#Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
#Override
public String toString() {
return "Saison{" +
"id=" + getId() +
", anneeSaison='" + getAnneeSaison() + "'" +
", estActiveSaison='" + getEstActiveSaison() + "'" +
"}";
}
}
And the Link Entity Seance :
#Entity
#Table(name = "seance")
#Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Seance implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
#SequenceGenerator(name = "sequenceGenerator")
private Long id;
#NotNull
#Column(name = "date_seance", nullable = false)
private LocalDate dateSeance;
#NotNull
#Pattern(regexp = "(^0{0,1}[0-9]|^[1]{1}[0-9]|^[2]{1}[0-3])H[0-5]{1}[0-9]{1}$")
#Column(name = "heure_debut_seance", nullable = false)
private String heureDebutSeance;
#ManyToOne
private Saison saison;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Seance id(Long id) {
this.id = id;
return this;
}
public LocalDate getDateSeance() {
return this.dateSeance;
}
public Seance dateSeance(LocalDate dateSeance) {
this.dateSeance = dateSeance;
return this;
}
public void setDateSeance(LocalDate dateSeance) {
this.dateSeance = dateSeance;
}
public String getHeureDebutSeance() {
return this.heureDebutSeance;
}
public Seance heureDebutSeance(String heureDebutSeance) {
this.heureDebutSeance = heureDebutSeance;
return this;
}
public void setHeureDebutSeance(String heureDebutSeance) {
this.heureDebutSeance = heureDebutSeance;
}
public Saison getSaison() {
return this.saison;
}
public Seance saison(Saison saison) {
this.setSaison(saison);
return this;
}
public void setSaison(Saison saison) {
this.saison = saison;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
#Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Seance)) {
return false;
}
return id != null && id.equals(((Seance) o).id);
}
#Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
#Override
public String toString() {
return "Seance{" +
"id=" + getId() +
", dateSeance='" + getDateSeance() + "'" +
", heureDebutSeance='" + getHeureDebutSeance() + "'" +
"}";
}
}
And this resource
#GetMapping("/saison/{id}")
public ResponseEntity<Saison> getSaisons(#PathVariable Long id) {
log.debug("REST request to get Saisons : {}", id);
Optional<Saison> saisons = saisonRepository.findById(id);
return ResponseUtil.wrapOrNotFound(saisons);
}
All properties are available including "seances"
In the frontend, I have a method for call the service :
changementSaisonDansListe(): void {
if (this.saisonIdSelectionnee) {
this.saisonService.find(this.saisonIdSelectionnee).subscribe(res => {
if (res.body) {
this.saisonSelectionnee = res.body;
}
}, () => {
// TODO Remplacer avec Gestion des erreurs
// this.loadAll();
})
}
}
And the service that points to the back :
find(id: number): Observable<EntityResponseType> {
return this.http.get<ISaison>(`${this.resourceUrlSaison}/${id}`, { observe: 'response' });
}
The endpoint :
public resourceUrlSaison = this.applicationConfigService.getEndpointFor('api/saison');
But when i check the content of the service return, properties "seance" is always null :
EDIT 1
The same with SOPAUI :
EDIT 2
Very strange ... if I put my backend in debug and I put a breakpoint before the return and I display in the debug console the value of the property "session", they are displayed on SOAPUi but only the ones I saw on the debugging console (and not the others)!
Found, my entity was not up to date with all the attributes (including "seance") because I added them after their generation ... it seems to work!

List not being saved

I'm trying to save a list of question options but its not being saved. Only the last row is being save.
Below is the code.
#Transactional
public void addQuestionOptions(QuestionOptionsRequest questionOptionsRequest, int questionId) {
List<QuestionOption> optionList = new ArrayList<>();
QuestionOption options = new QuestionOption();
Question question = questionRepository.findByQuestionId(questionId);
if(question != null) {
questionOptionsRequest.getQuestionOptions()
.stream()
.forEach(option -> {
options.setQuestionOption(option.getQuestionOption());
options.setQuestion(question);
options.setQuestionOptionNumber(option.getQuestionOptionNumber());
optionList.add(options);
});
questionOptionRepository.saveAll(optionList);
}
}
QuestionOption
#Entity
#JsonIgnoreProperties({"question"})
public class QuestionOption {
#Id
#GeneratedValue
private int questionOptionId;
private int questionOptionNumber;
private String questionOption;
public Question getQuestion() {
return question;
}
public void setQuestion(Question question) {
this.question = question;
}
#ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
private Question question;
public void setQuestionOptionNumber(int questionOptionNumber)
{
this.questionOptionNumber = questionOptionNumber;
}
public void setQuestionOption(String questionOption)
{
this.questionOption = questionOption;
}
public String getQuestionOption()
{
return this.questionOption;
}
public int getQuestionOptionNumber()
{
return this.questionOptionNumber;
}
public int getQuestionOptionId() {
return questionOptionId;
}
public void setQuestionOptionId(int questionOptionId) {
this.questionOptionId = questionOptionId;
}
}
Question
#Entity
#Getter
#Setter
public class Question {
#Id
#GeneratedValue
private int questionId;
private int assessmentId;
private QuestionTypes questionType;
private String questionText;
private String questionURL;
private QuestionStatus questionStatus;
#OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="question")
private List<QuestionOption> questionOptions;
public void setQuestionId(int queId)
{
this.questionId = queId;
}
public void setQuestionText(String queTxt)
{
this.questionText = queTxt;
}
public void setQuestionType(QuestionTypes queType)
{
this.questionType = queType;
}
public void setQuestionURL(String queURL)
{
this.questionURL = queURL;
}
public int getQuestionId() {
return questionId;
}
public String getQuestionText() {
return questionText;
}
public QuestionStatus getQuestionStatus() {
return questionStatus;
}
public void setQuestionStatus(QuestionStatus questionStatus) {
this.questionStatus = questionStatus;
}
public QuestionTypes getQuestionTypes() {
return this.questionType;
}
public String getQuestionURL() {
return this.questionURL;
}
public int getAssessmentId() {
return this.assessmentId;
}
public void setAssessmentId(int assessmentId) {
this.assessmentId = assessmentId;
}
public QuestionTypes getQuestionType() {
return questionType;
}
}
You are creating only one object of QuestionOption
QuestionOption options = new QuestionOption();
Create this object inside for each.

JPA: How to map one entity's property value to collection property of another entity

I have two entities, naming Sport and Image.
As the title above, how can I map the value of property, sportId at Sport to the #ManyToOne collection property at Image? For instance, I want the value of sportId (eg. 1) to be displayed at collection property field of sportId at Image. How can I achieve this?
Sport.java
#Views({#View(members= "title; date; estimatedCost; attendance; remark; images"),
#View(name="NoImagesCollection", members= "sportId; title; date; estimatedCost; attendance; remark")})
#Entity
public class Sport {
//******************************FORM ID******************************//
#Id
#Hidden
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name="SPORT_ID", length=10, unique = true, nullable = false, updatable = false)
private int sportId;
#NoCreate
#NoModify
#OneToMany(fetch = FetchType.LAZY,cascade=CascadeType.ALL,mappedBy="sports")
private Collection<Image> images;
//******************************TITLE******************************//
#Column(name="SPORT_TITLE", precision=2000)
#Required
private String title;
//******************************DATE START******************************//
// #Stereotype("DATE")
#Column(name="SPORT_DATE")
#Required
private Date date;
//******************************ESTIMATED COST******************************//
#Hidden
#Stereotype("MONEY")
#Column(name="SPORT_EST_COST")
#Required
private BigDecimal estimatedCost; // Include the import java.math.* BigDecimal is typically used for money
//******************************ESTIMATED ATTENDEES******************************//
#Hidden
#Column(name="SPORT_ATTENDANCE", length=10)
#Required
private int attendance;
//******************************REMARK******************************//
#Hidden
#Editor("TextAreaNoFrame")
#Stereotype("MEMO")
#Column(name="SPORT_REMARK", precision=2000)
private String remark;
//******************************ENTERED DATE******************************//
#Hidden
#Column(name="ENTERED_DATE")
#Temporal(TemporalType.TIMESTAMP)
private Date enteredDate;
#PrePersist
private void setCreateDate() {
enteredDate = new Date();
}
//******************************MODIFIED DATE******************************//
#Hidden
#Column(name="MODIFIED_DATE")
#Temporal(TemporalType.TIMESTAMP)
private Date modifiedDate;
#PostUpdate
private void updateModifyDate() {
modifiedDate = new Date();
}
//******************************GETTERS AND SETTERS FOR ALL PROPERTIES******************************//
public int getSportId() {
return sportId;
}
public void setSportId(int sportId) {
this.sportId = sportId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public BigDecimal getEstimatedCost() {
return estimatedCost;
}
public void setEstimatedCost(BigDecimal estimatedCost) {
this.estimatedCost = estimatedCost;
}
public int getAttendance() {
return attendance;
}
public void setAttendance(int attendance) {
this.attendance = attendance;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Date getEnteredDate() {
return enteredDate;
}
public void setEnteredDate(Date enteredDate) {
this.enteredDate = enteredDate;
}
public Date getModifiedDate() {
return modifiedDate;
}
public void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}
public Collection<Image> getImages() {
return images;
}
public void setImages(Collection<Image> images) {
this.images = images;
}
}
Image.java
#View(members="sports; image")
#Entity
public class Image {
#Id
#Hidden
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name="IMG_ID", unique = true, nullable = false, updatable = false)
private int imgId;
#Required
#Column(name="IMG_IMAGE")
#Stereotype("PHOTO")
private byte [] image;
#ReferenceView("NoImagesCollection")
#Required
#NoFrame
#ManyToOne(optional=true)
#JoinColumn(name="IMG_SPORT_ID", nullable = false)
private Sport sports;
#Hidden
#Column(name="ENTERED_DATE")
#Temporal(TemporalType.TIMESTAMP)
private Date penteredDate;
#PrePersist
private void setCreateDate() {
penteredDate = new Date();
}
#Hidden
#Column(name="MODIFIED_DATE")
#Temporal(TemporalType.TIMESTAMP)
private Date pmodifiedDate;
#PostUpdate
private void updateModifyDate() {
pmodifiedDate = new Date();
}
public int getImgId() {
return imgId;
}
public void setImgId(int imgId) {
this.imgId = imgId;
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public Sport getSports() {
return sports;
}
public void setSports(Sport sports) {
this.sports = sports;
}
public Date getPenteredDate() {
return penteredDate;
}
public void setPenteredDate(Date penteredDate) {
this.penteredDate = penteredDate;
}
public Date getPmodifiedDate() {
return pmodifiedDate;
}
public void setPmodifiedDate(Date pmodifiedDate) {
this.pmodifiedDate = pmodifiedDate;
}
}
ListSportImagesAction.java
public class ListSportImagesAction extends TabBaseAction implements IForwardAction {
private int row;
#Inject
private Tab tab;
public void execute() throws Exception {
Map sportKey = (Map) tab.getTableModel().getObjectAt(row);
int sportId = ((Integer) sportKey.get("sportId")).intValue();
Tab imageTab = (Tab)getContext().get("CkSurvey", getForwardURI(), "xava_tab");
imageTab.setBaseCondition("${sport.sportId} = " + sportId);
System.out.println("id================="+sportId);
}
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
public Tab getTab() {
return tab;
}
public void setTab(Tab tab) {
this.tab = tab;
}
#Override
public String getForwardURI() {
return "/m/Image";
}
#Override
public boolean inNewWindow() {
return true;
}
}
Any guidance provided will be appreciated.
--Edited--
I have added the code for the action that map the value. I fail to display the value at the property field, although it is displayed at Eclipse's console.

Rest Client: Javax.ws.rs

i'm starting with Rest and don't have no idea how to implement it properly. I got an exercise: i must implement a Rest-Client with the RestClient-API from javax.ws.rs standard library and i tried by using the code below, but i'm getting a null pointer exception. But the resource are there and when i try directly from the browser (http://localhost:8080/sep/rest/customers/112). Now my question how can i do it properly. Some constraints, i must use XML (not JSON) for the Data-support.
Hier my client-code:
public Response createCustomer(Customer customer){
log.info("Starting: Rest Create a Customer with Name: " + Customer.class.getName());
this.customerWebTarget = this.client.target(URL);
Response response = this.customerWebTarget.request().
buildPost(Entity.entity(customer, MediaType.APPLICATION_XML)).invoke();
log.info("Ending: Rest Create a Customer with Name: " + response.getEntity().getClass().getName());
return response;
}
CustomerResource-Code:
#Path("customers")
public class CustomerResource implements IAllowedMethods<Customer> {
private static final long serialVersionUID = -6367055402693237329L;
private Logger logger = Logger.getLogger(CustomerResource.class.getName());
#Inject
private CustomerService service;
public CustomerResource() {
logger.info("create of instance " + this.getClass().getName());
}
#Override
#GET
#Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response get() {
List<Customer> list = service.loadAll(Customer.FINDALL, Customer.class);
if (list != null && !list.isEmpty()) {
ResponseCustomerList responseList = new ResponseCustomerList();
responseList.setList(list);
return Response.ok(responseList).build();
}
return Response.status(Status.NOT_FOUND).build();
}
.
.
.
Customer Code:
import de.ostfalia.sep.adapter.XMLIntegerAdapter;
#XmlRootElement
#XmlAccessorType(XmlAccessType.FIELD)
public class Customer implements Serializable {
private static final long serialVersionUID = 80668466040239995L;
#XmlID
#XmlJavaTypeAdapter(XMLIntegerAdapter.class)
private Integer customerNumber;
private String customerName;
private String contactLastName;
private String contactFirstName;
private String phone;
private String addressLine1;
private String addressLine2;
private String city;
private String state;
private String postalCode;
private String country;
#XmlIDREF
private Employee salesRepEmployee;
private BigDecimal creditLimit;
private Set<Payment> payments;
private Set<Order> orders;
public Customer() {
}
public Customer(Integer customernumber) {
this.customerNumber = customernumber;
}
public Customer(Integer customerNumber, String customerName, String contactLastName, String contactFirstName,
String phone, String addressLine1, String city, String country) {
this.customerNumber = customerNumber;
this.customerName = customerName;
this.contactLastName = contactLastName;
this.contactFirstName = contactFirstName;
this.phone = phone;
this.addressLine1 = addressLine1;
this.city = city;
this.country = country;
}
public Integer getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(Integer customerNumber) {
this.customerNumber = customerNumber;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getContactLastName() {
return contactLastName;
}
public void setContactLastName(String contactLastName) {
this.contactLastName = contactLastName;
}
public String getContactFirstName() {
return contactFirstName;
}
public void setContactFirstName(String contactFirstName) {
this.contactFirstName = contactFirstName;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddressLine1() {
return addressLine1;
}
public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}
public String getAddressLine2() {
return addressLine2;
}
public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Employee getSalesRepEmployee() {
return salesRepEmployee;
}
public void setSalesRepEmployee(Employee salesRepEmployee) {
this.salesRepEmployee = salesRepEmployee;
}
public BigDecimal getCreditLimit() {
return creditLimit;
}
public void setCreditLimit(BigDecimal creditLimit) {
this.creditLimit = creditLimit;
}
#Override
public int hashCode() {
int hash = 0;
hash += (customerNumber != null ? customerNumber.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are
// not set
if (!(object instanceof Customer)) {
return false;
}
Customer other = (Customer) object;
if ((this.customerNumber == null && other.customerNumber != null)
|| (this.customerNumber != null && !this.customerNumber.equals(other.customerNumber))) {
return false;
}
return true;
}
#Override
public String toString() {
return customerNumber.toString();
}
public Set<Payment> getPayments() {
return payments;
}
public void setPayments(Set<Payment> payments) {
this.payments = payments;
}
public Set<Order> getOrders() {
return orders;
}
public void setOrders(Set<Order> orders) {
this.orders = orders;
}
}
Instead of response.getEntity(), use response.readEntity(String.class) to get the data as a String. If you want to deserialize it to a POJO, then just pass that class to the readEntity.
Also you should make sure to check the status code (response.getStatus()) to make sure it's a success status.

JavaFX properties fail to persist

I'm using some JavaFX properties in my app:
#Entity(name = "Klanten")
#Table(name = "Klanten")
#NamedQueries({
#NamedQuery(name = "Klanten.findAll", query = "select k from Klanten k")
})
public class Klant implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int klantId;
#Transient
private final SimpleStringProperty naam = new SimpleStringProperty();
//private String naam;
//private String straat;
#Transient
private final SimpleStringProperty straat = new SimpleStringProperty();
private String telefoon;
private String huisnummer;
private String gsm;
private String woonplaats;
private String email;
private String postcode;
#OneToMany(mappedBy = "Klant", cascade = CascadeType.REMOVE)
private List<Raam> ramen;
public Klant() {
}
public Klant(String naam) {
this.naam.set(naam);
}
#Override
public String toString() {
return this.naam.get();
}
#Access(AccessType.PROPERTY)
#Column(name="naam")
public String getNaam() {
return this.naam.get();
}
public void setNaam(String naam){
this.naam.set(naam);
}
public List<Raam> getRamen() {
return this.ramen;
}
#Id
public int getKlantId() {
return klantId;
}
public void setKlantId(int klantId) {
this.klantId = klantId;
}
#Access(AccessType.PROPERTY)
#Column(name="straat")
public String getStraat() {
return straat.get();
}
public void setStraat(String straat) {
this.straat.set(straat);
}
public String getTelefoon() {
return telefoon;
}
public void setTelefoon(String telefoon) {
this.telefoon = telefoon;
}
public String getHuisnummer() {
return huisnummer;
}
public void setHuisnummer(String huisnummer) {
this.huisnummer = huisnummer;
}
public String getGsm() {
return gsm;
}
public void setGsm(String gsm) {
this.gsm = gsm;
}
public String getWoonplaats() {
return woonplaats;
}
public void setWoonplaats(String woonplaats) {
this.woonplaats = woonplaats;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPostcode() {
return postcode;
}
public void setPostcode(String postcode) {
this.postcode = postcode;
}
public StringProperty naamProperty() {
return naam;
}
public StringProperty straatProperty() {
return straat;
}
}
However when I let JPA generate my database, the column "naam" and "straat" aren't generated. I get no error. How can I resolve this?
I tried all the things listed here:
Possible solution 1
Possible solution 2
These didn't work.
You can try to use regular properties and then have another get method which returns a new SimpleStringProperty, i.e.:
public StringProperty naamProperty() {
return new SimpleStringProperty(naam);
}
public StringProperty straatProperty() {
return new SimpleStringProperty(straat);
}