hibernate one to many annotation confusion - java

I'm not understanding how to do something that is probably very easy to do. I have a table named "Composer". A "Composer" can have many compositions ("Composition" table). I get the following error when I run this through Spring Boot:
19:11:40 web.1 | Caused by: org.hibernate.AnnotationException:
mappedBy reference an unknown target entity property:
com.zack.music.domain.Composition.composition in com.zack.music.domain.Composer.compositions
Below are my entity classes. What am I doing wrong here?
package com.zack.music.domain;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Date;
import java.util.*;
#Entity
public class Composer implements Serializable {
#Id
private String name;
private Date birth;
private Date death;
#OneToMany(mappedBy="composition")
private List<Composition> compositions;
protected Composer() { }
public Composer(String name, Date birth, Date death) {
this.name = name;
this.birth = birth;
this.death = death;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public Date getDeath() {
return death;
}
public void setDeath(Date death) {
this.death = death;
}
public List<Composition> getCompositions() {
return compositions;
}
public void setCompositions(List<Composition> compositions) {
this.compositions = compositions;
}
}
#Entity
public class Composition implements Serializable {
#Id
#Column(nullable = false)
private String name;
#ManyToOne
private Composer composer;
protected Composition() { }
public Composition(String name, Composer composer) {
this.name = name;
this.composer = composer;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Composer getComposer() {
return composer;
}
public void setComposer(Composer composer) {
this.composer = composer;
}
}

mappedBy is telling hibernate the property name on the related entity that owns the relationship. There is no property named 'composition' on the related entity: Composition. You probably just meant for the value of mappedBy to be "composer".

I was able to solve it using #ElementCollection. Java Persistence/ElementCollection helped me figure it out. I also filled in the "name" attributes on all of my tables and columns which I think helped identify everything. Here are the updated entities that are working:
package com.zack.music.domain;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Date;
import java.util.*;
#Entity(name="COMPOSER")
public class Composer implements Serializable {
#Id
#Column(name="NAME", nullable = false)
private String name;
#Column(name="BIRTH", nullable = false)
private Date birth;
#Column(name="DEATH", nullable = true)
private Date death;
#ElementCollection
#CollectionTable(
name="COMPOSITION",
joinColumns=#JoinColumn(name="COMPOSER", referencedColumnName="NAME")
)
#Column(name="NAME")
private List<String> compositions;
protected Composer() { }
public Composer(String name, Date birth, Date death) {
this.name = name;
this.birth = birth;
this.death = death;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public Date getDeath() {
return death;
}
public void setDeath(Date death) {
this.death = death;
}
public List<String> getCompositions() {
return compositions;
}
}
#Entity(name="COMPOSITION")
public class Composition implements Serializable {
#Id
#Column(name="NAME", nullable = false)
private String name;
#Column(name="COMPOSER", nullable = false)
private String composer;
protected Composition() { }
public Composition(String name, String composer) {
this.name = name;
this.composer = composer;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getComposer() {
return composer;
}
public void setComposer(String composer) {
this.composer = composer;
}
}

Related

Java multiple join query

I am trying to create a REST service in Java with Spring Boot.
I have 2 tables Topic and Course and i want to retrieve NAME and DESCRIPTION from Topic and PRICE from Course.
The connection between these 2 tables is made with TOPIC_ID from Course.
Result MUST be a JSON.
[
{
"id": "course1",
"name": "name course1",
"description": "course1"
},
{
"id": "course2",
"name": "course2 name",
"description": "course2"
},
{
"id": "course3",
"name": "course3 name",
"description": "course3"
}
]
The query is below.
I know it's possible with DTO and JPA but I need to write a lot of code for a simple database query.
Thank you.
package com.example.course;
import com.example.topic.Topic;
import javax.persistence.*;
#Entity
#Table(name = "topic", schema = "topic")
public class Topic {
#Id
private String id;
private String name;
private String description;
public Topic() {
}
public Topic(String id, String name, String description) {
this.id = id;
this.name = name;
this.description = description;
}
public String getDescription() {
return description;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDescription(String description) {
this.description = description;
}
}
package com.example.topic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "course", schema = "topic")
public class Course {
#Id
#Column(name = "ID")
private String id;
#Column(name = "NAME")
private String name;
#Column(name = "DESCRIPTION")
private String description;
#Column(name="PRICE")
private Integer price;
#ManyToOne
#JoinColumn(name="TOPIC_ID", nullable=false)
private Topic topic;
public Course() {
}
public Course(String id, String name, String description, String topicId) {
this.id = id;
this.name = name;
this.description = description;
this.topic = new Topic(topicId, "", "");
}
public String getDescription() {
return description;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDescription(String description) {
this.description = description;
}
public Topic getTopic() {
return topic;
}
public void setTopic(Topic topic) {
this.topic = topic;
}
public void setPrice(Integer price) { this.price = price; }
public Integer getPrice() { return price; }
}
package com.example.dto;
public class TopicDescDTO {
private String id;
private String name;
private String description;
public TopicDescDTO(String id, String name, String description) {
this.id = id;
this.name = name;
this.description = description;
}
public TopicDescDTO() {
}
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;
}
}
select t.name, t.description, c.price as course_price
from topic.course c
inner join topic.topic t on t.id = c.topic_id
Take advantage of the projection interface offered by Spring Data JPA:
public interface TopicDescDTO{
Integer getPrice();
String getName();
String getDescription();
}
and then just land a proper method in one of your repositories:
#Query(select t.name, t.description, c.price
from Course c
inner join c.topic t)
List<TopicDescDTO> getTopicDescs();
Spring will do the mapping for you.

Cannot delete resource in Spring Hateoas

I have a spring boot application which exposes resources using Spring HATEOAS. All the method GET, POST, PATCH works fine except DELETE. When I send a delete request to a resource, it returns 204 No content response but when I request for all resource, the item which I deleted appears again. No exception is logged on the console. No error in postman request.
The resource I am trying to delete is having many-to-one association with another POJO. But those resources which doesn't have many-to-one(some have one-to-many) is getting deleted.
The Mode Entity
#Entity
#Table(name="Modes")
public class Mode {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
#OneToMany(mappedBy = "mode", fetch=FetchType.EAGER, cascade = CascadeType.ALL)
private Set<Expense> expense;
public Mode() {}
#Autowired
public Mode(String name,Set<Expense> expense) {
this.name = name;
this.expense = expense;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
The Category Entity
#Entity
#Table(name="Categories")
public class Category {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
#OneToMany(mappedBy = "category", fetch=FetchType.EAGER, cascade = CascadeType.ALL)
private Set<Expense> expense;
public Category() { }
#Autowired
public Category(String name, Set<Expense> expense) {
this.setName(name);
this.expense = expense;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
The Expense Entity
#Entity
#Table(name="Expenses")
public class Expense {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private BigDecimal amount;
#ManyToOne
#JoinColumn(name="categoryId")
private Category category;
#ManyToOne
#JoinColumn(name="modeId")
private Mode mode;
private Date date;
public Expense() {}
public Expense(String name, BigDecimal amount, Category category, Mode mode, Date date) {
this.name = name;
this.amount = amount;
this.category = category;
this.mode = mode;
this.date = date;
}
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;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public Mode getMode() {
return mode;
}
public void setMode(Mode mode) {
this.mode = mode;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
The repositories I used
public interface CategoryRepository extends CrudRepository<Category, Integer> {
}
public interface ExpenseRepository extends CrudRepository<Expense, Integer> {
}
public interface ModeRepository extends CrudRepository<Mode, Integer> {
}
The delete request for Expense is not working
I use MySQL as database and use Postman to test the URL
Try Changing from the cascade cascade = CascadeType.ALL)
and set cascade = CascadeType.REMOVE, orphanRemoval = true it should work
Read the docs for more information:
https://docs.oracle.com/cd/E19798-01/821-1841/giqxy/

Can't save child objects with OneToMany Relationship in Springboot/Hibernate

I am building an order tracking system in Spring Boot, using Hibernate annotations and Repositories. I have an Order class, which can have a list of OrderItems. These map to a ORDER and ORDER_ITEMS table respectively. The code I have representing the two is below.
Order.java
package net.township.order;
import org.hibernate.annotations.Cascade;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Set;
#Entity
#Table(name = "orders")
public class Order {
public Order() {
}
public Order(long merchantId, String firstDeliveryName, String
lastDeliveryName, String deliveryAddress, String status, Date createDate,
Date updateDate) {
this.merchantId = merchantId;
this.lastDeliveryName = lastDeliveryName;
this.firstDeliveryName = firstDeliveryName;
this.deliveryAddress = deliveryAddress;
this.status = status;
this.createDate = createDate;
this.updateDate = updateDate;
}
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "order_id", unique = true)
private long orderId;
#Column(name = "merchant_id")
private long merchantId;
#Column(name = "first_delivery_name")
private String firstDeliveryName;
#Column(name = "last_delivery_name")
private String lastDeliveryName;
#Column(name = "delivery_address")
private String deliveryAddress;
#Column
private String status;
#OneToMany(mappedBy = "order", cascade = {
CascadeType.ALL,CascadeType.PERSIST,CascadeType.MERGE })
private List<OrderItem> orderItems;
#Column(name = "create_date")
private Date createDate;
#Column(name = "update_date")
private Date updateDate;
public void setOrderId(long orderId) {
this.orderId = orderId;
}
public long getMerchantId() {
return merchantId;
}
public void setMerchantId(long merchantId) {
this.merchantId = merchantId;
}
public List<OrderItem> getOrderItems() {
return orderItems;
}
public void setOrderItems(List<OrderItem> orderItems) {
this.orderItems = orderItems;
}
public String getLastDeliveryName() {
return lastDeliveryName;
}
public void setLastDeliveryName(String lastDeliveryName) {
this.lastDeliveryName = lastDeliveryName;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public String getFirstDeliveryName() {
return firstDeliveryName;
}
public void setFirstDeliveryName(String firstDeliveryName) {
this.firstDeliveryName = firstDeliveryName;
}
public String getDeliveryAddress() {
return deliveryAddress;
}
public void setDeliveryAddress(String deliveryAddress) {
this.deliveryAddress = deliveryAddress;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
}
OrderItem.java
package net.township.order;
import com.fasterxml.jackson.annotation.JsonBackReference;
import org.hibernate.annotations.Cascade;
import javax.persistence.*;
#Entity
#Table(name = "order_items")
public class OrderItem {
#Id
#GeneratedValue
#Column(name = "id")
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
#Column
private String name;
#Column
private String description;
#Column
private Long quantity;
#ManyToOne(fetch=FetchType.LAZY)
#JoinColumn (name="ORDER_ID")
#JsonBackReference
#Cascade(value={org.hibernate.annotations.CascadeType.ALL})
private Order order;
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 Long getQuantity() {
return quantity;
}
public void setQuantity(Long quantity) {
this.quantity = quantity;
}
}
When I POST a new Order from my front-end, it is mapped to an Order object correctly. All OrderItems that were provided in the JSON are present in the object as a List as well. However, after I save it to the database using my OrderRepository's save method (it's just a CrudRepository), my database contains a new Order object with the correct fields, but nothing is ever created in ORDER_ITEMS.
I've poked around the documentation for both Hibernate and JPA OneToMany annotations, and I don't see where I'm going wrong here. I'll also add that I'm doing no manual schema creation, letting SpringBoot handle setting up everything in H2 for me.
This is what ultimately worked for me.
Order.java
package net.township.order;
import org.hibernate.annotations.Cascade;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Set;
#Entity
#Table(name = "orders")
public class Order {
public Order() {
}
public Order(long merchantId, String firstDeliveryName, String lastDeliveryName, String deliveryAddress, String status, Date createDate, Date updateDate) {
this.merchantId = merchantId;
this.lastDeliveryName = lastDeliveryName;
this.firstDeliveryName = firstDeliveryName;
this.deliveryAddress = deliveryAddress;
this.status = status;
this.createDate = createDate;
this.updateDate = updateDate;
}
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "order_id", unique = true)
private long orderId;
#Column(name = "merchant_id")
private long merchantId;
#Column(name = "first_delivery_name")
private String firstDeliveryName;
#Column(name = "last_delivery_name")
private String lastDeliveryName;
#Column(name = "delivery_address")
private String deliveryAddress;
#Column
private String status;
#OneToMany( cascade = CascadeType.ALL)
#JoinColumn(name = "order_id", referencedColumnName = "order_id")
private List<OrderItem> orderItems;
#Column(name = "create_date")
private Date createDate;
#Column(name = "update_date")
private Date updateDate;
public void setOrderId(long orderId) {
this.orderId = orderId;
}
public long getMerchantId() {
return merchantId;
}
public void setMerchantId(long merchantId) {
this.merchantId = merchantId;
}
public List<OrderItem> getOrderItems() {
return orderItems;
}
public void setOrderItems(List<OrderItem> orderItems) {
this.orderItems = orderItems;
}
public String getLastDeliveryName() {
return lastDeliveryName;
}
public void setLastDeliveryName(String lastDeliveryName) {
this.lastDeliveryName = lastDeliveryName;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public String getFirstDeliveryName() {
return firstDeliveryName;
}
public void setFirstDeliveryName(String firstDeliveryName) {
this.firstDeliveryName = firstDeliveryName;
}
public String getDeliveryAddress() {
return deliveryAddress;
}
public void setDeliveryAddress(String deliveryAddress) {
this.deliveryAddress = deliveryAddress;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
}
OrderItem.java
package net.township.order;
import com.fasterxml.jackson.annotation.JsonBackReference;
import javax.persistence.*;
#Entity
#Table(name = "order_items")
public class OrderItem {
#Id
#GeneratedValue
#Column(name = "id")
private Long id;
#Column(name = "order_id")
private Long orderId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
#Column
private String name;
#Column
private String description;
#Column
private Long quantity;
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 Long getQuantity() {
return quantity;
}
public void setQuantity(Long quantity) {
this.quantity = quantity;
}
}
Add CascadeType.ALL to your mapping.

How can I save a list in google-app-engine database?

I have the following code that is not working properly.
testprovincia exist on data base and the partidos variable is a list that I am sure is not empty but is never persisted too.
mgr = getPersistenceManager();
Query query = mgr.newQuery(Provincia.class);
query.setFilter("name == nameParam");
query.declareParameters("String nameParam");
List<Provincia> results = (List<Provincia>) query.execute("testprovincia");
Provincia prov = results.get(0);
insertPartidos(partidos);
prov.setPartidos(partidos);
mgr.makePersistent(prov);
query.closeAll();
mgr.close();
InsertPartidos method:
private void insertPartidos(List<Partido> partidos){
for (Partido partido : partidos) {
log.info(partido.getName());
mgr.makePersistent(partido);
}
}
The question is why I never see the list I added to prov variable on the database? Is allways empty.
Here are my classes:
#PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Provincia {
public Provincia(String name) {
super();
this.name = name;
}
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
#Persistent
private String name;
#Persistent(mappedBy = "provincia")
#Order(extensions = #Extension(vendorName="datanucleus",key="list-ordering", value="name asc"))
private List<Partido> partidos;
public Key getId() {
return id;
}
public void setId(Key id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Partido> getPartidos() {
return partidos;
}
public void setPartidos(List<Partido> partidos) {
this.partidos = partidos;
}
}
#PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Partido {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
#Persistent
private String name;
#Persistent
private Provincia provincia;
public Partido(){
}
public Partido(Key id) {
super();
this.id = id;
}
public Partido(Key id, String name, Provincia prov) {
super();
this.id = id;
this.name = name;
this.provincia = prov;
}
public Partido(String name, Provincia prov) {
super();
this.name = name;
this.provincia = prov;
}
public Key getId() {
return id;
}
public void setId(Key id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Provincia getProvincia() {
return provincia;
}
public void setProvincia(Provincia provincia) {
this.provincia = provincia;
}
}
Maybe using the other way of updating. If testprovincia already exists, using the method described here might do the trick for you. Instead of using makepersistent, grab your data with the persistence manager and straight update it.
That or use standard datastore's db (or ndb) puts, as explained here? Do you REALLY need the JDO?

Getting HTTP Error 500 while mapping JAXB classes

I'm just learning to develop a REST application using JAXB and JPA. I'm stuck in weird problem and I have no clue what to search for.
I have these two classes:
package clinic.model;
import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlList;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.oxm.annotations.XmlInverseReference;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* The persistent class for the patients database table.
*
*/
#Entity
#Table(name="patients")
#NamedQuery(name="Patient.findAll", query="SELECT p FROM Patient p")
#XmlRootElement
public class Patient implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String address;
private String area;
#Temporal(TemporalType.DATE)
private Date dob;
private BigDecimal mobile;
private String name;
private String sex;
//bi-directional many-to-one association to Prescription
#OneToMany(mappedBy="patient")
private List<Prescription> prescriptions;
public Patient() {
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
public String getArea() {
return this.area;
}
public void setArea(String area) {
this.area = area;
}
public Date getDob() {
return this.dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public BigDecimal getMobile() {
return this.mobile;
}
public void setMobile(BigDecimal mobile) {
this.mobile = mobile;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return this.sex;
}
public void setSex(String sex) {
this.sex = sex;
}
#XmlList
public List<Prescription> getPrescriptions() {
return this.prescriptions;
}
public void setPrescriptions(List<Prescription> prescriptions) {
this.prescriptions = prescriptions;
}
public Prescription addPrescription(Prescription prescription) {
getPrescriptions().add(prescription);
prescription.setPatient(this);
return prescription;
}
public Prescription removePrescription(Prescription prescription) {
getPrescriptions().remove(prescription);
prescription.setPatient(null);
return prescription;
}
}
And
package clinic.model;
import java.io.Serializable;
import javax.persistence.*;
import org.eclipse.persistence.oxm.annotations.XmlInverseReference;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* The persistent class for the prescriptions database table.
*
*/
#Entity
#Table(name="prescriptions")
#NamedQuery(name="Prescription.findAll", query="SELECT p FROM Prescription p")
public class Prescription implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
#Temporal(TemporalType.DATE)
private Date date;
private BigDecimal fee;
#Temporal(TemporalType.DATE)
private Date followup;
private String treatment;
//bi-directional many-to-one association to Patient
#ManyToOne(fetch=FetchType.LAZY)
private Patient patient;
//bi-directional many-to-many association to Diagnosis
#ManyToMany
#JoinTable(
name="prescriptions_diagnoses"
, joinColumns={
#JoinColumn(name="pid")
}
, inverseJoinColumns={
#JoinColumn(name="did")
}
)
private List<Diagnosis> diagnoses;
//bi-directional many-to-one association to PrescriptionDrug
#OneToMany(mappedBy="prescription")
private List<PrescriptionDrug> prescriptionsDrugs;
//bi-directional many-to-many association to Vaccine
#ManyToMany(mappedBy="prescriptions")
private List<Vaccine> vaccines;
public Prescription() {
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public Date getDate() {
return this.date;
}
public void setDate(Date date) {
this.date = date;
}
public BigDecimal getFee() {
return this.fee;
}
public void setFee(BigDecimal fee) {
this.fee = fee;
}
public Date getFollowup() {
return this.followup;
}
public void setFollowup(Date followup) {
this.followup = followup;
}
public String getTreatment() {
return this.treatment;
}
public void setTreatment(String treatment) {
this.treatment = treatment;
}
public Patient getPatient() {
return this.patient;
}
public void setPatient(Patient patient) {
this.patient = patient;
}
public List<Diagnosis> getDiagnoses() {
return this.diagnoses;
}
public void setDiagnoses(List<Diagnosis> diagnoses) {
this.diagnoses = diagnoses;
}
public List<PrescriptionDrug> getPrescriptionsDrugs() {
return this.prescriptionsDrugs;
}
public void setPrescriptionsDrugs(List<PrescriptionDrug> prescriptionsDrugs) {
this.prescriptionsDrugs = prescriptionsDrugs;
}
public PrescriptionDrug addPrescriptionsDrug(PrescriptionDrug prescriptionsDrug) {
getPrescriptionsDrugs().add(prescriptionsDrug);
prescriptionsDrug.setPrescription(this);
return prescriptionsDrug;
}
public PrescriptionDrug removePrescriptionsDrug(PrescriptionDrug prescriptionsDrug) {
getPrescriptionsDrugs().remove(prescriptionsDrug);
prescriptionsDrug.setPrescription(null);
return prescriptionsDrug;
}
public List<Vaccine> getVaccines() {
return this.vaccines;
}
public void setVaccines(List<Vaccine> vaccines) {
this.vaccines = vaccines;
}
}
When I have a patient entry in the database, the service is able to map entities into XML/JSON. But when I add an associating prescription entry, Glassfish throws error 500.
What could be the problem?
I'm using GlassFish 4.0 and EclipseLink 2.5.1. IDE is Eclipse Luna.
Solution found at http://blog.bdoughan.com/2010/07/jpa-entities-to-xml-bidirectional.html
The exception can be seen if a string is returned instead of the POJO object and the marshaling is done manually.

Categories

Resources