Hibernate many to many selects wrong column - java

SOLVED: I had an error at the place where I called for the getAllergies! There is nothing wrong with this setup.
I'm currently working on a project involving Spring and Hibernate and got an issue with a ManyToMany relation.
These are the java classes:
Patient.java
package medicapp.models.impl;
import javax.persistence.*;
import java.sql.Date;
import java.util.List;
#Entity
#Table(name="patient")
public class Patient {
#Id
#Column(name="Id")
private int id;
#Column(name="NatNumber")
private String nationalNumber;
#Column(name="FirstName")
private String firstName;
#Column(name="LastName")
private String lastName;
#Column(name="Address")
private String address;
#ManyToOne(cascade = {CascadeType.ALL})
#JoinColumn(name="birthplace")
private Municipality birthPlace;
#ManyToOne(cascade = {CascadeType.ALL})
#JoinColumn(name="zipcode")
private Municipality municipality;
#ManyToOne(cascade = {CascadeType.ALL})
#JoinColumn(name="healthinsuranceid")
private HealthInsurance healthInsurance;
#Column(name="Nationality")
private String nationality;
#Column(name="ContactName")
private String contactName;
#Column(name="ContactNumber")
private String contactNumber;
#Column(name="Phone")
private String phone;
#Column(name="Email")
private String email;
#Column(name="Gender")
private char gender;
#Column(name="DateOfBirth")
private Date birthDate;
#Column(name="Smoker")
private boolean smoker;
// Geen Idee hoe we dat gaan doen, effe opgelost door transient te gebruiken, moet nog worden gecheckt
#ManyToOne(cascade = {CascadeType.ALL})
#JoinColumn(name="bloodgroupid")
private BloodType bloodType;
#ManyToOne(cascade = {CascadeType.ALL})
#JoinColumn(name="juridicalid")
private Juridical juridical;
#ManyToMany
#JoinTable(name = "allergypatient",
joinColumns = #JoinColumn(name="PatientId"),
inverseJoinColumns = #JoinColumn(name = "AllergyId")
)
private List<Allergy> allergies;
#ManyToMany
#JoinTable(name = "medicationpatient",
joinColumns = #JoinColumn(name="PatientId"),
inverseJoinColumns = #JoinColumn(name = "MedicationId")
)
//#Transient
private List<Medication> medications;
#ManyToMany
#JoinTable(name = "chronicdiseasepatient",
joinColumns = #JoinColumn(name="PatientId"),
inverseJoinColumns = #JoinColumn(name = "ChronicDiseaseId")
)
//#Transient
private List<Disease> diseases;
#ManyToMany
#JoinTable(name = "vaccinationpatient",
joinColumns = #JoinColumn(name="PatientId"),
inverseJoinColumns = #JoinColumn(name = "VaccinationId")
)
//#Transient
private List<Vaccination> vaccinations;
#Column(name="lastwill")
private boolean lastWill;
/**
*
* #param id
* #param nationalNumber
* #param firstName
* #param lastName
* #param address
* #param birthPlace
* #param municipality
* #param healthInsurance
* #param nationality
* #param gender
* #param birthDate
*/
public Patient(int id, String nationalNumber, String firstName, String lastName, String address, Municipality birthPlace, Municipality municipality, HealthInsurance healthInsurance, String nationality, char gender, Date birthDate) {
this.id = id;
this.nationalNumber = nationalNumber;
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.birthPlace = birthPlace;
this.municipality = municipality;
this.healthInsurance = healthInsurance;
this.nationality = nationality;
this.gender = gender;
this.birthDate = birthDate;
}
/**
* Default Constructor without parameters, this is required for using Hibernate
*/
public Patient() {
}
/**
* #param firstName
* #param lastName
* #param address
* #param municipality
* #param birthDate Patient constructor with the minum required values
*/
public Patient(String firstName, String lastName, String address, Municipality municipality, Date birthDate) {
this.firstName = firstName;
this.address = address;
this.municipality = municipality;
this.lastName = lastName;
this.birthDate = birthDate;
}
public Patient(String firstName, String lastName, String address,Date birthDate){
this.firstName = firstName;
this.address = address;
this.lastName = lastName;
this.birthDate = birthDate;
}
public Patient(String firstName, String lastName, String address, Municipality municipality, Municipality birthPlace, String nationalNumber, String nationality, char gender, Date birthDate, String phone, String email, Boolean smoker, Juridical juridical, BloodType bloodType, HealthInsurance healthInsurance, String contactName, String contactNumber, boolean lastWill) {
this.address = address;
this.birthDate = birthDate;
this.birthPlace = birthPlace;
this.firstName = firstName;
this.gender = gender;
this.lastName = lastName;
this.nationality = nationality;
this.nationalNumber = nationalNumber;
this.municipality = municipality;
this.juridical = juridical;
this.lastWill = lastWill;
this.healthInsurance = healthInsurance;
this.bloodType = bloodType;
this.phone = phone;
this.email = email;
this.smoker = smoker;
this.contactName = contactName;
this.contactNumber = contactNumber;
}
/**
* #param firstName
* #param lastName
* #param address
* #param municipality
* #param birthPlace
* #param nationalNumber
* #param nationality
* #param gender
* #param birthDate
* Patient constructor that uses all the values retrieved from the e-ID
* #author Geert Peters
*/
public Patient(String firstName, String lastName, String address, Municipality municipality, Municipality birthPlace, String nationalNumber, String nationality, char gender, Date birthDate) {
this.address = address;
this.birthDate = birthDate;
this.birthPlace = birthPlace;
this.firstName = firstName;
this.gender = gender;
this.lastName = lastName;
this.nationality = nationality;
this.nationalNumber = nationalNumber;
this.municipality = municipality;
}
/**
* #param allergy adds an allergy to a patient's file
*/
public void addAllergy(Allergy allergy) {
this.allergies.add(allergy);
}
/**
* #param disease adds a disease to a patient's file
*/
public void addDisease(Disease disease) {
this.diseases.add(disease);
}
/**
* #param medication adds a medication to a patient's file
*/
public void addMedication(Medication medication) {
this.medications.add(medication);
}
/**
* #param vaccination adds a vaccination to a patient's file
*/
public void addVaccination(Vaccination vaccination) {
this.vaccinations.add(vaccination);
}
/**
* #param medication removes a medication from the list
*/
public void removeMedication(Medication medication) {
this.medications.remove(medication);
}
/**
* Gets smoker.
*
* #return Value of smoker.
*/
public boolean isSmoker() {
return smoker;
}
/**
* Gets birthPlace.
*
* #return Value of birthPlace.
*/
public Municipality getBirthPlace() {
return birthPlace;
}
/**
* Sets new id.
*
* #param id New value of id.
*/
public void setId(int id) {
this.id = id;
}
/**
* Sets new smoker.
*
* #param smoker New value of smoker.
*/
public void setSmoker(boolean smoker) {
this.smoker = smoker;
}
/**
* Gets id.
*
* #return Value of id.
*/
public int getId() {
return id;
}
/**
* Gets address.
*
* #return Value of address.
*/
public String getAddress() {
return address;
}
/**
* Sets new lastName.
*
* #param lastName New value of lastName.
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* Gets gender.
*
* #return Value of gender.
*/
public char getGender() {
return gender;
}
/**
* Gets nationalNumber.
*
* #return Value of nationalNumber.
*/
public String getNationalNumber() {
return nationalNumber;
}
/**
* Gets firstName.
*
* #return Value of firstName.
*/
public String getFirstName() {
return firstName;
}
/**
* Gets municipality.
*
* #return Value of municipality.
*/
public Municipality getMunicipality() {
return municipality;
}
/**
* Sets new nationalNumber.
*
* #param nationalNumber New value of nationalNumber.
*/
public void setNationalNumber(String nationalNumber) {
this.nationalNumber = nationalNumber;
}
/**
* Sets new nationality.
*
* #param nationality New value of nationality.
*/
public void setNationality(String nationality) {
this.nationality = nationality;
}
/**
* Sets new municipality.
*
* #param municipality New value of municipality.
*/
public void setMunicipality(Municipality municipality) {
this.municipality = municipality;
}
/**
* Gets phone.
*
* #return Value of phone.
*/
public String getPhone() {
return phone;
}
/**
* Sets new gender.
*
* #param gender New value of gender.
*/
public void setGender(char gender) {
this.gender = gender;
}
/**
* Gets contactNumber.
*
* #return Value of contactNumber.
*/
public String getContactNumber() {
return contactNumber;
}
/**
* Gets lastName.
*
* #return Value of lastName.
*/
public String getLastName() {
return lastName;
}
/**
* Sets new address.
*
* #param address New value of address.
*/
public void setAddress(String address) {
this.address = address;
}
/**
* Sets new firstName.
*
* #param firstName New value of firstName.
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* Sets new birthPlace.
*
* #param birthPlace New value of birthPlace.
*/
public void setBirthPlace(Municipality birthPlace) {
this.birthPlace = birthPlace;
}
/**
* Gets nationality.
*
* #return Value of nationality.
*/
public String getNationality() {
return nationality;
}
/**
* Gets contactName.
*
* #return Value of contactName.
*/
public String getContactName() {
return contactName;
}
/**
* Gets birthDate.
*
* #return Value of birthDate.
*/
public Date getBirthDate() {
return birthDate;
}
/**
* Sets new contactName.
*
* #param contactName New value of contactName.
*/
public void setContactName(String contactName) {
this.contactName = contactName;
}
/**
* Sets new phone.
*
* #param phone New value of phone.
*/
public void setPhone(String phone) {
this.phone = phone;
}
/**
* Sets new contactNumber.
*
* #param contactNumber New value of contactNumber.
*/
public void setContactNumber(String contactNumber) {
this.contactNumber = contactNumber;
}
/**
* Sets new birthDate.
*
* #param birthDate New value of birthDate.
*/
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
/**
* Gets vaccinations.
*
* #return Value of vaccinations.
*/
public List<Vaccination> getVaccinations() {
return vaccinations;
}
/**
* Gets allergies.
*
* #return Value(Set) of allergies.
*/
public List<Allergy> getAllergies() {
return allergies;
}
/**
* Gets diseases.
*
* #return Value(List) of diseases.
*/
public List<Disease> getDiseases() {
return diseases;
}
/**
* Gets medications.
*
* #return Value(List) of medications.
*/
public List<Medication> getMedications() {
return medications;
}
/**
* Gets bloodgroup.
*
* #return Value of bloodgroup.
*/
public BloodType getBloodType() {
return bloodType;
}
/**
* Sets new bloodgroup.
*
* #param bloodType New value of bloodgroup.
*/
public void setBloodType(BloodType bloodType) {
this.bloodType = bloodType;
}
/**
* Gets HealthInsurance.
*
* #return Value of HealthInsureance.
*/
public HealthInsurance getHealthInsurance() {
return healthInsurance;
}
/**
* Sets new HealthInsurance.
*
* #param healthInsurance New value of HealthInsurance.
*/
public void setHealthInsurance(HealthInsurance healthInsurance) {
this.healthInsurance = healthInsurance;
}
/**
* Gets email.
*
* #return Value of email.
*/
public String getEmail() {
return email;
}
/**
* Sets new lastWill.
*
* #param lastWill New value of lastWill.
*/
public void setLastWill(boolean lastWill) {
this.lastWill = lastWill;
}
/**
* Sets new juridical.
*
* #param juridical New value of juridical.
*/
public void setJuridical(Juridical juridical) {
this.juridical = juridical;
}
/**
* Sets new allergies.
*
* #param allergies New value of allergies.
*/
public void setAllergies(List<Allergy> allergies) {
this.allergies = allergies;
}
/**
* Sets new diseases.
*
* #param diseases New value of diseases.
*/
public void setDiseases(List<Disease> diseases) {
this.diseases = diseases;
}
/**
* Gets lastWill.
*
* #return Value of lastWill.
*/
public boolean isLastWill() {
return lastWill;
}
/**
* Gets juridical.
*
* #return Value of juridical.
*/
public Juridical getJuridical() {
return juridical;
}
/**
* Sets new medications.
*
* #param medications New value of medications.
*/
public void setMedications(List<Medication> medications) {
this.medications = medications;
}
/**
* Sets new email.
*
* #param email New value of email.
*/
public void setEmail(String email) {
this.email = email;
}
/**
* Sets new vaccinations.
*
* #param vaccinations New value of vaccinations.
*/
public void setVaccinations(List<Vaccination> vaccinations) {
this.vaccinations = vaccinations;
}
}
Allergy.java
package medicapp.models.impl;
import javax.persistence.*;
import java.util.List;
#Entity
#Table(name="allergy")
public class Allergy {
#Id
#Column(name="Id")
#GeneratedValue
private int id;
#Column(name = "Description")
private String description;
#ManyToMany(mappedBy = "allergies")
private List<Patient> patients;
/**
* Default Constructor without parameters, this is required for using Hibernate
*/
public Allergy(){
}
/**
*
* #param description
*/
public Allergy(String description){
this.description = description;
}
/**
* Sets new id.
*
* #param id New value of id.
*/
public void setId(int id) {
this.id = id;
}
/**
* Sets new description.
*
* #param description New value of description.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Gets description.
*
* #return Value of description.
*/
public String getDescription() {
return description;
}
/**
* Gets id.
*
* #return Value of id.
*/
public int getId() {
return id;
}
}
Now, if I would call the getAllergies from a Patient object, it will generate this SQL code:
select
allergies0_.PatientId as PatientI1_11_0_,
allergies0_.AllergyId as AllergyI2_1_0_,
allergy1_.Id as Id1_0_1_,
allergy1_.Description as Descript2_0_1_
from
allergypatient allergies0_
inner join
allergy allergy1_
on allergies0_.AllergyId=allergy1_.Id
where
allergies0_.PatientId=?
This would mean I get these results:
2 3 3 Lactose
2 5 5 Animals
2 5 5 Animals
2 19 19 Pennicilline
Now if I print out the Description of the Allergy instances, it will always give me Hay, since that is the Allergy with id 2.
I need to have the second column to be the column that gets used to get the Allergies. Is there a way for me to change this?
Kind regards

You can specify join collumns with jpa/ which hibernate implements.Here is an example
#ManyToMany
#JoinTable(
name="EMP_PROJ",
joinColumns={#JoinColumn(name="EMP_ID", referencedColumnName="ID")},
inverseJoinColumns={#JoinColumn(name="PROJ_ID", referencedColumnName="ID")})
private List projects;

Related

Create Dynamic JPA Query

I have a view with many fields as query filters, and I am using JPA derived queries , however creating all queries for every combination of fields/filters would be tedious and long.
I found out that I can create a dynamic query for it, but not sure how.
So far I have created these queries in my repository, but still need a lot more :
public interface EmployeeReportInfoViewRepository extends PagingAndSortingRepository<EmployeeReportInfo, Long> {
List<EmployeeReportInfo> findByControlNumber(String controlNmber);
List<EmployeeReportInfo> findByManager(String manager);
List<EmployeeReportInfo> findByofficeLocation(String officeLocation);
List<EmployeeReportInfo> findByBenchFlag(char benchFlag);
List<EmployeeReportInfo> findByBillableFlag(char billableFlag);
List<EmployeeReportInfo> findByEnableFlag(boolean enableFlag);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumber(String lastName, String firstName,String controlNumber);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumberAndManager(String lastName, String firstName,String controlNmber,String manager);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumberAndManagerAndOfficeLocation(String lastName, String firstName,String controlNmber,String manager,String officeLocation);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumberAndManagerAndOfficeLocationAndBenchFlag(String lastName, String firstName,String controlNmber,String manager,String officeLocation, char benchFlag);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumberAndManagerAndOfficeLocationAndBenchFlagAndBillableFlag(String lastName, String firstName,String controlNmber,String manager,String officeLocation, char benchFlag,char bllableFlag);
List<EmployeeReportInfo> findByLastNameAndFirstNameAndControlNumberAndManagerAndOfficeLocationAndBenchFlagAndBillableFlagAndEnableFlagAndStartGreaterThanEqualAndEndLessThanEqual
(String lastName, String firstName,String controlNmber,String manager,String officeLocation, char benchFlag,char bllableFlag,
boolean emableFlag, Date start,Date end);
}
#Entity
#Table(name = "employee_report_view")
public class EmployeeReportInfo {
#Id
#Column(name = "employee_id")
private Long id;
private String name;
private Date start;
private Date end;
#Column(name = "control_number")
private String controlNumber;
#Column(name = "enable_flag")
private boolean enableFlag;
#Column(name = "billable_flag")
private char billableFlag;
#Column(name = "bench_flag")
private char benchFlag;
#Column(name = "office_location")
private String officeLocation;
#Column(name = "manager")
private String manager;
/**
* #return the id
*/
public Long getId() {
return id;
}
/**
* #return the name
*/
public String getName() {
return name;
}
/**
* #param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* #param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* #return the start
*/
public Date getStart() {
return start;
}
/**
* #param start the start to set
*/
public void setStart(Date start) {
this.start = start;
}
/**
* #return the end
*/
public Date getEnd() {
return end;
}
/**
* #param end the end to set
*/
public void setEnd(Date end) {
this.end = end;
}
/**
* #return the controlNumber
*/
public String getControlNumber() {
return controlNumber;
}
/**
* #param controlNumber the controlNumber to set
*/
public void setControlNumber(String controlNumber) {
this.controlNumber = controlNumber;
}
/**
* #return the enableFlag
*/
public boolean isEnableFlag() {
return enableFlag;
}
/**
* #param enableFlag the enableFlag to set
*/
public void setEnableFlag(boolean enableFlag) {
this.enableFlag = enableFlag;
}
/**
* #return the billableFlag
*/
public char getBillableFlag() {
return billableFlag;
}
/**
* #param billableFlag the billableFlag to set
*/
public void setBillableFlag(char billableFlag) {
this.billableFlag = billableFlag;
}
/**
* #return the benchFlag
*/
public char getBenchFlag() {
return benchFlag;
}
/**
* #param benchFlag the benchFlag to set
*/
public void setBenchFlag(char benchFlag) {
this.benchFlag = benchFlag;
}
/**
* #return the officeLocation
*/
public String getOfficeLocation() {
return officeLocation;
}
/**
* #param officeLocation the officeLocation to set
*/
public void setOfficeLocation(String officeLocation) {
this.officeLocation = officeLocation;
}
/**
* #return the manager
*/
public String getManager() {
return manager;
}
/**
* #param manager the manager to set
*/
public void setManager(String manager) {
this.manager = manager;
}
}
I can understand your needs:you want to dynamically generate query conditions based on the url issued by the form.Let's assume that the url maps to the back end to a HashMap<String,String>.
For instance,url:
127.0.0.1/employees?nameContains=jack&ageEquals=10
Map:
HashMap<String, String>:key:nameContains,value:jack,key:ageEuqals,value:10
The Spring framework can do this mapping automatically(RequestParamMapMethodArgumentResolver). What you need to do is to dynamically generate the Specification(Specification) by this map.
Gets the type of property corresponding to the field using reflect : name=>String, age=>Integer
Using CriteriaBuilder to build query criteria,it has comprehensive api,such as:
Predicate like(Expression x, String pattern); => contains
Predicate equal(Expression x, Expression y); => equal
Assemble your query criteria(or,and)
You get a Specification.
This is a relatively complex solution idea, which requires the coordination between the front table component and the back end, but it will be very convenient.
What I said is relatively simple and general, there are a lot of details.(such as nested properties,one-to-one,one-to-many,etc)
Also,You can have a look http://www.querydsl.com/

Retrofit 2 (in Android) after implementation, Where are my JSON elements?

I'm implementing a retrofit 2 interface to parse JSON elements (video urls, thumbnails, title etc.)
JSONschema2Pojo resulted in 4 pojo classes, but the main/root one is VideoInfo (never mind implements Parcelable, I'm not yet doing anything with it)
Is the lack of #SerializedName("....") affects anything, knowing that this was automatically generated by jsonschema2pojo ? UPDATE : generated new pojo classes, this time with Gson annotations (#SerializedName("") and #Expose) but still having the same problem.
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.List;
public class VideoInfo implements Parcelable {
private List<Item> items = new ArrayList<Item>();
private int pageNumber;
private int pageSize;
private int totalCount;
/**
* No args constructor for use in serialization
*
*/
public VideoInfo() {
}
/**
*
* #param totalCount
* #param items
* #param pageSize
* #param pageNumber
*/
public VideoInfo(List<Item> items, int pageNumber, int pageSize, int totalCount) {
this.items = items;
this.pageNumber = pageNumber;
this.pageSize = pageSize;
this.totalCount = totalCount;
}
/**
*
* #return
* The items
*/
public List<Item> getItems() {
return items;
}
/**
*
* #param items
* The items
*/
public void setItems(List<Item> items) {
this.items = items;
}
/**
*
* #return
* The pageNumber
*/
public int getPageNumber() {
return pageNumber;
}
/**
*
* #param pageNumber
* The page_number
*/
public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
}
/**
*
* #return
* The pageSize
*/
public int getPageSize() {
return pageSize;
}
/**
*
* #param pageSize
* The page_size
*/
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
/**
*
* #return
* The totalCount
*/
public int getTotalCount() {
return totalCount;
}
/**
*
* #param totalCount
* The total_count
*/
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
}
}
UPDATE: in the class VideoInfo above you can see private List<Item> items = new ArrayList<Item>(); this is because there's another pojo class that has a list of tiems, as follows:
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
public class Item {
#SerializedName("id")
#Expose
private int id;
#SerializedName("name")
#Expose
private String name;
#SerializedName("shortDescription")
#Expose
private String shortDescription;
#SerializedName("creationDate")
#Expose
private String creationDate;
#SerializedName("publishedDate")
#Expose
private String publishedDate;
#SerializedName("linkURL")
#Expose
private String linkURL;
#SerializedName("linkText")
#Expose
private String linkText;
#SerializedName("tags")
#Expose
private List<String> tags = new ArrayList<String>();
#SerializedName("videoStillURL")
#Expose
private String videoStillURL;
#SerializedName("thumbnailURL")
#Expose
private String thumbnailURL;
#SerializedName("length")
#Expose
private int length;
#SerializedName("renditions")
#Expose
private List<Rendition> renditions = new ArrayList<Rendition>();
#SerializedName("IOSRenditions")
#Expose
private List<IOSRendition> IOSRenditions = new ArrayList<IOSRendition>();
#SerializedName("HDSRenditions")
#Expose
private List<Object> HDSRenditions = new ArrayList<Object>();
/**
* No args constructor for use in serialization
*
*/
public Item() {
}
/**
*
* #param tags
* #param videoStillURL
* #param HDSRenditions
* #param id
* #param creationDate
* #param IOSRenditions
* #param linkText
* #param shortDescription
* #param renditions
* #param name
* #param linkURL
* #param length
* #param publishedDate
* #param thumbnailURL
*/
public Item(int id, String name, String shortDescription, String creationDate, String publishedDate, String linkURL, String linkText, List<String> tags, String videoStillURL, String thumbnailURL, int length, List<Rendition> renditions, List<IOSRendition> IOSRenditions, List<Object> HDSRenditions) {
this.id = id;
this.name = name;
this.shortDescription = shortDescription;
this.creationDate = creationDate;
this.publishedDate = publishedDate;
this.linkURL = linkURL;
this.linkText = linkText;
this.tags = tags;
this.videoStillURL = videoStillURL;
this.thumbnailURL = thumbnailURL;
this.length = length;
this.renditions = renditions;
this.IOSRenditions = IOSRenditions;
this.HDSRenditions = HDSRenditions;
}
/**
*
* #return
* The id
*/
public int getId() {
return id;
}
/**
*
* #param id
* The id
*/
public void setId(int id) {
this.id = id;
}
/**
*
* #return
* The name
*/
public String getName() {
return name;
}
/**
*
* #param name
* The name
*/
public void setName(String name) {
this.name = name;
}
/**
*
* #return
* The shortDescription
*/
public String getShortDescription() {
return shortDescription;
}
/**
*
* #param shortDescription
* The shortDescription
*/
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
/**
*
* #return
* The creationDate
*/
public String getCreationDate() {
return creationDate;
}
/**
*
* #param creationDate
* The creationDate
*/
public void setCreationDate(String creationDate) {
this.creationDate = creationDate;
}
/**
*
* #return
* The publishedDate
*/
public String getPublishedDate() {
return publishedDate;
}
/**
*
* #param publishedDate
* The publishedDate
*/
public void setPublishedDate(String publishedDate) {
this.publishedDate = publishedDate;
}
/**
*
* #return
* The linkURL
*/
public String getLinkURL() {
return linkURL;
}
/**
*
* #param linkURL
* The linkURL
*/
public void setLinkURL(String linkURL) {
this.linkURL = linkURL;
}
/**
*
* #return
* The linkText
*/
public String getLinkText() {
return linkText;
}
/**
*
* #param linkText
* The linkText
*/
public void setLinkText(String linkText) {
this.linkText = linkText;
}
/**
*
* #return
* The tags
*/
public List<String> getTags() {
return tags;
}
/**
*
* #param tags
* The tags
*/
public void setTags(List<String> tags) {
this.tags = tags;
}
/**
*
* #return
* The videoStillURL
*/
public String getVideoStillURL() {
return videoStillURL;
}
/**
*
* #param videoStillURL
* The videoStillURL
*/
public void setVideoStillURL(String videoStillURL) {
this.videoStillURL = videoStillURL;
}
/**
*
* #return
* The thumbnailURL
*/
public String getThumbnailURL() {
return thumbnailURL;
}
/**
*
* #param thumbnailURL
* The thumbnailURL
*/
public void setThumbnailURL(String thumbnailURL) {
this.thumbnailURL = thumbnailURL;
}
/**
*
* #return
* The length
*/
public int getLength() {
return length;
}
/**
*
* #param length
* The length
*/
public void setLength(int length) {
this.length = length;
}
/**
*
* #return
* The renditions
*/
public List<Rendition> getRenditions() {
return renditions;
}
/**
*
* #param renditions
* The renditions
*/
public void setRenditions(List<Rendition> renditions) {
this.renditions = renditions;
}
/**
*
* #return
* The IOSRenditions
*/
public List<IOSRendition> getIOSRenditions() {
return IOSRenditions;
}
/**
*
* #param IOSRenditions
* The IOSRenditions
*/
public void setIOSRenditions(List<IOSRendition> IOSRenditions) {
this.IOSRenditions = IOSRenditions;
}
/**
*
* #return
* The HDSRenditions
*/
public List<Object> getHDSRenditions() {
return HDSRenditions;
}
/**
*
* #param HDSRenditions
* The HDSRenditions
*/
public void setHDSRenditions(List<Object> HDSRenditions) {
this.HDSRenditions = HDSRenditions;
}
}
UPDATE: So above you can see that we have defined private List<Rendition> renditions = new ArrayList<Rendition>(); that is defined in another pojo classes Rendition.class:
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Rendition {
#SerializedName("audioOnly")
#Expose
private boolean audioOnly;
#SerializedName("controllerType")
#Expose
private String controllerType;
#SerializedName("displayName")
#Expose
private String displayName;
#SerializedName("encodingRate")
#Expose
private int encodingRate;
#SerializedName("frameHeight")
#Expose
private int frameHeight;
#SerializedName("frameWidth")
#Expose
private int frameWidth;
#SerializedName("id")
#Expose
private int id;
#SerializedName("referenceId")
#Expose
private Object referenceId;
#SerializedName("remoteStreamName")
#Expose
private Object remoteStreamName;
#SerializedName("remoteUrl")
#Expose
private Object remoteUrl;
#SerializedName("size")
#Expose
private int size;
#SerializedName("uploadTimestampMillis")
#Expose
private int uploadTimestampMillis;
#SerializedName("url")
#Expose
private String url;
#SerializedName("videoCodec")
#Expose
private String videoCodec;
#SerializedName("videoContainer")
#Expose
private String videoContainer;
#SerializedName("videoDuration")
#Expose
private int videoDuration;
/**
* No args constructor for use in serialization
*
*/
public Rendition() {
}
/**
*
* #param controllerType
* #param encodingRate
* #param referenceId
* #param url
* #param size
* #param id
* #param uploadTimestampMillis
* #param frameWidth
* #param remoteUrl
* #param videoContainer
* #param remoteStreamName
* #param displayName
* #param videoCodec
* #param videoDuration
* #param audioOnly
* #param frameHeight
*/
public Rendition(boolean audioOnly, String controllerType, String displayName, int encodingRate, int frameHeight, int frameWidth, int id, Object referenceId, Object remoteStreamName, Object remoteUrl, int size, int uploadTimestampMillis, String url, String videoCodec, String videoContainer, int videoDuration) {
this.audioOnly = audioOnly;
this.controllerType = controllerType;
this.displayName = displayName;
this.encodingRate = encodingRate;
this.frameHeight = frameHeight;
this.frameWidth = frameWidth;
this.id = id;
this.referenceId = referenceId;
this.remoteStreamName = remoteStreamName;
this.remoteUrl = remoteUrl;
this.size = size;
this.uploadTimestampMillis = uploadTimestampMillis;
this.url = url;
this.videoCodec = videoCodec;
this.videoContainer = videoContainer;
this.videoDuration = videoDuration;
}
/**
*
* #return
* The audioOnly
*/
public boolean isAudioOnly() {
return audioOnly;
}
/**
*
* #param audioOnly
* The audioOnly
*/
public void setAudioOnly(boolean audioOnly) {
this.audioOnly = audioOnly;
}
/**
*
* #return
* The controllerType
*/
public String getControllerType() {
return controllerType;
}
/**
*
* #param controllerType
* The controllerType
*/
public void setControllerType(String controllerType) {
this.controllerType = controllerType;
}
/**
*
* #return
* The displayName
*/
public String getDisplayName() {
return displayName;
}
/**
*
* #param displayName
* The displayName
*/
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
/**
*
* #return
* The encodingRate
*/
public int getEncodingRate() {
return encodingRate;
}
/**
*
* #param encodingRate
* The encodingRate
*/
public void setEncodingRate(int encodingRate) {
this.encodingRate = encodingRate;
}
/**
*
* #return
* The frameHeight
*/
public int getFrameHeight() {
return frameHeight;
}
/**
*
* #param frameHeight
* The frameHeight
*/
public void setFrameHeight(int frameHeight) {
this.frameHeight = frameHeight;
}
/**
*
* #return
* The frameWidth
*/
public int getFrameWidth() {
return frameWidth;
}
/**
*
* #param frameWidth
* The frameWidth
*/
public void setFrameWidth(int frameWidth) {
this.frameWidth = frameWidth;
}
/**
*
* #return
* The id
*/
public int getId() {
return id;
}
/**
*
* #param id
* The id
*/
public void setId(int id) {
this.id = id;
}
/**
*
* #return
* The referenceId
*/
public Object getReferenceId() {
return referenceId;
}
/**
*
* #param referenceId
* The referenceId
*/
public void setReferenceId(Object referenceId) {
this.referenceId = referenceId;
}
/**
*
* #return
* The remoteStreamName
*/
public Object getRemoteStreamName() {
return remoteStreamName;
}
/**
*
* #param remoteStreamName
* The remoteStreamName
*/
public void setRemoteStreamName(Object remoteStreamName) {
this.remoteStreamName = remoteStreamName;
}
/**
*
* #return
* The remoteUrl
*/
public Object getRemoteUrl() {
return remoteUrl;
}
/**
*
* #param remoteUrl
* The remoteUrl
*/
public void setRemoteUrl(Object remoteUrl) {
this.remoteUrl = remoteUrl;
}
/**
*
* #return
* The size
*/
public int getSize() {
return size;
}
/**
*
* #param size
* The size
*/
public void setSize(int size) {
this.size = size;
}
/**
*
* #return
* The uploadTimestampMillis
*/
public int getUploadTimestampMillis() {
return uploadTimestampMillis;
}
/**
*
* #param uploadTimestampMillis
* The uploadTimestampMillis
*/
public void setUploadTimestampMillis(int uploadTimestampMillis) {
this.uploadTimestampMillis = uploadTimestampMillis;
}
/**
*
* #return
* The url
*/
public String getUrl() {
return url;
}
/**
*
* #param url
* The url
*/
public void setUrl(String url) {
this.url = url;
}
/**
*
* #return
* The videoCodec
*/
public String getVideoCodec() {
return videoCodec;
}
/**
*
* #param videoCodec
* The videoCodec
*/
public void setVideoCodec(String videoCodec) {
this.videoCodec = videoCodec;
}
/**
*
* #return
* The videoContainer
*/
public String getVideoContainer() {
return videoContainer;
}
/**
*
* #param videoContainer
* The videoContainer
*/
public void setVideoContainer(String videoContainer) {
this.videoContainer = videoContainer;
}
/**
*
* #return
* The videoDuration
*/
public int getVideoDuration() {
return videoDuration;
}
/**
*
* #param videoDuration
* The videoDuration
*/
public void setVideoDuration(int videoDuration) {
this.videoDuration = videoDuration;
}
}
I have created a retrofit interface VideoInterface.class
import retrofit2.Call;
import retrofit2.http.GET;
/**
* retrofit 2 interface
*/
public interface VideoInterface {
String apiURL = ".....";
#GET(apiURL)
public Call<VideosResponse> listVideos();
}
I have created a response/parse class VideosResponse.java
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.List;
/**
*/
public class VideosResponse {
//initalizing the collection
List<VideoInfo> videos;
public VideosResponse() {
videos = new ArrayList<VideoInfo>();
}
//parsing the response
public static VideosResponse parseJSON(String response) {
Gson gson = new GsonBuilder().create();
VideosResponse videosResponse = gson.fromJson(response, VideosResponse.class);
return videosResponse;
}
}
UPDATED :Finally I'm calling the API , but not able to get the individual elements
I know I should be able to do something like response.body().getItem().getID().getRendition().getUrl() for example, but I don't see it in the auto complete and if I write it I get errors.
This code is in my onResume() method , the reason why I've commented out public static below is because it's not allowed within the onResume()
// Creating a simple REST adapter which points the API
// public static
final String BASE_URL = "http://api......";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
// Creating an instance of our API interface.
VideoInterface service = retrofit.create(VideoInterface.class);
Call<VideosResponse> call = service.listVideos();
call.enqueue(new Callback<VideosResponse>() {
#Override
public void onResponse(Call<VideosResponse> call, Response<VideosResponse> response) {
VideosResponse videoResponse = response.body();
}
#Override
public void onFailure(Call<VideosResponse> call, Throwable t) {
}});
Everything to the last step seems be alright (no errors), the following logs gives me:
Log.d("Videos ", response.message()); //OK
Log.d("Videos ", String.valueOf(response.isSuccess())); //TRUE
Log.d("Videos ", String.valueOf(response.code())); //200
but I'm still not able to get the strings I need. When I print the log for the response show the response VideosResponse videoResponse = response.body(); I get : VideosResponse#3b8bfaa4 , is this normal? how can I use this?
Is using parcelable advised? will it change anything?
You need to show us the json response or you can figure out on your own also. Basically the object attributes name must match the json attributes, you can debug to see whether the elements are receiving the value or not, in case they are not then add the SerializedName annotation to it. From there onwards there are two possibilities either you have an object or an array. For which you can further create a POJO or create a attribute of type List.
I know I should be able to do something like response.body().item.getID() for example
Um, no, not based on the code as I understand it.
response here would appear to be Response<VideosResponse> response
response.body() therefore would be a VideosResponse
response.body().item will fail, as VideosResponse does not have an item field
When I print the log for the response show the response VideosResponse videoResponse = response.body(); I get : VideosResponse#3b8bfaa4 , is this normal?
Yes. That is the default toString() output for a Java object that has not overridden toString(). This shows that response.body() is a VideosResponse.
I have created a response/parse class VideosResponse.java
Then you know that VideosResponse does not have anything named item. Gson does not add methods to your classes; it only populates instances of those classes, based on parsing some JSON.
If you are expecting VideosResponse to have an item field, make sure that exists in your JSON, and then edit VideosResponse to have an item field.
add a toString() to your VideoInfo class and then onResponse you can log the single object of the returned list with something like
for (VideoInfo videoInfo : videoResponses)
Log.d(LOG_TAG, "VideoInfo: " + videoInfo.toString());

How to add a object to a sorted set that's within a hashmap of objects

I'm trying to add a passenger object into a sorted set. This sorted set is in a cruise object. All of the cruise objects are within a hashMap. I'm kinda new to collections so I'm having trouble. This is my attempt to do what I'm doing.
HashMap<String, Cruise> cruiseMap = new HashMap<String, Cruise>();
SortedSet<Passenger> passengerSet = new TreeSet<Passenger>();
Queue<Passenger> waitingList = new LinkedList<Passenger>();
Cruise cruise = new Cruise("1", passengerSet, waitingList, false);
cruiseMap.put("1", cruise);
Passenger passenger = new Passenger("Smith", "J");
cruiseMap.get("1").getPassengerSet().add(passenger);
The passenger's parameters are strings that are last name then their first initial. The cruise's parameters are as a string the date, the sortedSet passengers, there's a queue for waiting list and a boolean variable to determine if the ship has departed. I keep getting tons of errors when I run this code. Thanks in advance for the help.
Here are the errors I'm recieving.
Exception in thread "main" java.lang.ClassCastException: edu.ilstu.Passenger cannot be cast to java.lang.Comparable
at java.util.TreeMap.compare(Unknown Source)
at java.util.TreeMap.put(Unknown Source)
at java.util.TreeSet.add(Unknown Source)
at edu.ilstu.Driver.main(Driver.java:48)
Passenger Class
public class Passenger {
private String lastName = "";
private String firstName = "";
public Passenger()
{
lastName = "no last name yet";
firstName = "no first name yet";
}
public Passenger(String lastName, String firstName)
{
this.lastName = lastName;
this.firstName = firstName;
}
/**
* #return the lastName
*/
public String getLastName()
{
return lastName;
}
/**
* #param lastName the lastName to set
*/
public void setLastName(String lastName)
{
this.lastName = lastName;
}
/**
* #return the firstName
*/
public String getFirstName()
{
return firstName;
}
/**
* #param firstName the firstName to set
*/
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
/* (non-Javadoc)
* #see java.lang.Object#toString()
*/
#Override
public String toString()
{
return lastName + " " + firstName;
}
}
Cruise Class
public class Cruise
{
private String day = "";
private SortedSet<Passenger> passengerSet = new TreeSet<Passenger>();
private Queue<Passenger> waitingList = new LinkedList<Passenger>();
private boolean hasDeparted = false;
public Cruise()
{
day = "no day yet";
passengerSet = null;
waitingList = null;
hasDeparted = false;
}
public Cruise(String day, SortedSet<Passenger> passengerSet, Queue<Passenger> waitingList, boolean hasDeparted)
{
this.day = day;
this.passengerSet = passengerSet;
this.waitingList = waitingList;
this.hasDeparted = hasDeparted;
}
/**
* #return the day
*/
public String getDay()
{
return day;
}
/**
* #param day the day to set
*/
public void setDay(String day)
{
this.day = day;
}
/**
* #return the passengerSet
*/
public SortedSet<Passenger> getPassengerSet()
{
return passengerSet;
}
/**
* #param passengerSet the passengerSet to set
*/
public void setPassengerSet(SortedSet<Passenger> passengerSet)
{
this.passengerSet = passengerSet;
}
/**
* #return the waitingList
*/
public Queue<Passenger> getWaitingList()
{
return waitingList;
}
/**
* #param waitingList the waitingList to set
*/
public void setWaitingList(Queue<Passenger> waitingList)
{
this.waitingList = waitingList;
}
/**
* #return the hasDeparted
*/
public boolean isHasDeparted()
{
return hasDeparted;
}
/**
* #param hasDeparted the hasDeparted to set
*/
public void setHasDeparted(boolean hasDeparted)
{
this.hasDeparted = hasDeparted;
}
}
It happens because your passengerSet is TreeSet (SortedSet), which means it will sort itself after each adding, because TreeSet is ordered set and has certain sequence unlike usual HashMap. Every SortedMap must know how to sort elements it contains. This can be done two ways:
You can implement your class from Comparable<T> interface.
You can add custom Comparator<T> to your SortedMap.
So, you have three ways to fix it (may be more, but three of them - are obvious):
Get rid of SortedMap, let's say replace your SortedMap to Map and replace TreeMap to HashMap in your code.
Add custom comparator to your passengerSet
HashMap<String, Cruise> cruiseMap = new HashMap<String, Cruise>();
SortedSet<Passenger> passengerSet = new TreeSet<Passenger>(new Comparator<Passenger>() {
#Override
public int compare(Passenger lhs, Passenger rhs) {
return lhs.getFirstName().compareTo(rhs.getFirstName());
}
});
Queue<Passenger> waitingList = new LinkedList<>();
Cruise cruise = new Cruise("1", passengerSet, waitingList, false);
cruiseMap.put("1", cruise);
Passenger passenger = new Passenger("Smith", "J");
cruiseMap.get("1").getPassengerSet().add(passenger);
Implement the Comparable<T> interface in your Passenger class.
public class Passenger implements Comparable<Passenger> {
private String lastName = "";
private String firstName = "";
public Passenger()
{
lastName = "no last name yet";
firstName = "no first name yet";
}
public Passenger(String lastName, String firstName)
{
this.lastName = lastName;
this.firstName = firstName;
}
/**
* #return the lastName
*/
public String getLastName()
{
return lastName;
}
/**
* #param lastName the lastName to set
*/
public void setLastName(String lastName)
{
this.lastName = lastName;
}
/**
* #return the firstName
*/
public String getFirstName()
{
return firstName;
}
/**
* #param firstName the firstName to set
*/
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
/* (non-Javadoc)
* #see java.lang.Object#toString()
*/
#Override
public String toString()
{
return lastName + " " + firstName;
}
#Override
public int compareTo(Passenger another) {
return firstName.compareTo(another.firstName);
}
}

JPA- Showing User Role relationships with Many to Many Hashset ENUMs

My DTO is being stored using JPA Hibernate and I'm able to store the other fields but having trouble trying to store this relationship for the user. The userRoleSet HashSet has ENUMs that represent what roles that user has. Some users with have no roles while someone will have 1 to 3 roles. Each role is different. How would I got about representing this in my database and using JPA? At the moment, the #ManyToMany doesn't work, I miss be missing something else? Essentially, I need to be able to query that specific user in the database and have it return the roles that is assigned to that user.
UserType Enums
public enum UserType
{
ALPHA,BRAVO,CHARLIE
}
Default User DTO JPA
#Entity
#Table(name = "users")
public class DefaultUser implements Serializable
{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "user_id")
private long user_id;
#Column(name = "user_name")
private String user_name;
#Column(name = "first_name")
private String firstName;
#Column(name = "last_name")
private String lastName;
#Column(name = "password")
private String password;
#ManyToMany
private Set<UserType> userRoleSet = new HashSet<UserType>();
/**
* #return the userTypes
*/
public Set<UserType> getUserTypes()
{
return userRoleSet;
}
/**
*
* #param userTypes
* the userTypes to set
*/
public void setUserTypes(Set<UserType> userTypes)
{
this.userRoleSet = userTypes;
}
/**
* #return the user_id
*/
public long getUser_id()
{
return user_id;
}
/**
* #return the user_name
*/
public String getUser_name()
{
return user_name;
}
/**
* #return the firstName
*/
public String getFirstName()
{
return firstName;
}
/**
* #return the lastName
*/
public String getLastName()
{
return lastName;
}
/**
* #return the password
*/
public String getPassword()
{
return password;
}
/**
* #param user_id
* the user_id to set
*/
public void setUser_id(long user_id)
{
this.user_id = user_id;
}
/**
* #param user_name
* the user_name to set
*/
public void setUser_name(String user_name)
{
this.user_name = user_name;
}
/**
* #param firstName
* the firstName to set
*/
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
/**
* #param lastName
* the lastName to set
*/
public void setLastName(String lastName)
{
this.lastName = lastName;
}
/**
* #param password
* the password to set
*/
public void setPassword(String password)
{
this.password = password;
}
}
The #ManyToMany annotation is used to map an association between two entities. For collections of simple types, the annotation to use is #ElementCollection.
PS: you always read and post the complete and exact error message you get when something "doesn't work".

org.hibernate.QueryException: could not resolve property

This is the first time that I use JPA. I write the code with Java and JPA. My code is below.
String queryStr = "SELECT m.title, b.isbn, b.authors";
queryStr += " FROM Book b, Media m";
queryStr += " WHERE m.MediaID = b.MediaID";
queryStr += " AND b.isbn = '" + isbn + "' AND m.title = '%" + title +"%'";
Query query = em.createQuery(queryStr);
From my code, Class Book extends class Media.
But I got the error which is
org.hibernate.QueryException: could not resolve property: MediaID of: mediaManagement.Media [SELECT m.title, b.isbn, b.authors FROM mediaManagement.Book b, mediaManagement.Media m WHERE m.MediaID = b.MediaID ]
This is the Media class.
#Entity
#Inheritance(strategy = InheritanceType.JOINED)
#Table(name = "Media")
#NamedQuery(name = "findAllMedias", query = "select b from Media b")
public class Media {
#Id
#Column(name = "MediaID")
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int mediaID;
/**
* Getter of the property <tt>mediaID</tt>
*
* #return Returns the mediaID.
* #uml.property name="mediaID"
*/
public int getMediaID() {
return mediaID;
}
/**
* Setter of the property <tt>mediaID</tt>
*
* #param mediaID
* The mediaID to set.
* #uml.property name="mediaID"
*/
public void setMediaID(int mediaID) {
this.mediaID = mediaID;
}
/**
* #uml.property name="title"
*/
#Column(name = "title")
private String title;
/**
* Getter of the property <tt>title</tt>
*
* #return Returns the title.
* #uml.property name="title"
*/
public String getTitle() {
return title;
}
/**
* Setter of the property <tt>title</tt>
*
* #param title
* The title to set.
* #uml.property name="title"
*/
public void setTitle(String title) {
this.title = title;
}
/**
* #uml.property name="editionDate"
*/
private Calendar editionDate;
/**
* Getter of the property <tt>editionDate</tt>
*
* #return Returns the editionDate.
* #uml.property name="editionDate"
*/
public Calendar getEditionDate() {
return editionDate;
}
/**
* Setter of the property <tt>editionDate</tt>
*
* #param editionDate
* The editionDate to set.
* #uml.property name="editionDate"
*/
public void setEditionDate(Calendar editionDate) {
this.editionDate = editionDate;
}
/*
* Two medias are equal if their mediaID is the same
*/
#Override
public boolean equals(Object media) {
if (media == null)
return false;
Media b = (Media) media;
if (b.mediaID == mediaID)
return true;
return false;
}
public Media() {
};
/**
* Creates a media All parameters should be given
*
* #param title
* the title of the media
*
* #param editionDate
* date of the edition of the media
*
* #throws BadParametersException
*/
public Media(String title, Calendar editionDate)
throws BadParametersException {
if ((title == null) || (editionDate == null))
throw new BadParametersException();
this.title = title;
this.editionDate = editionDate;
}
/**
* Returns a description of the media
*/
public String toString() {
return this.title + " " + String.valueOf(this.title);
}
/**
* #uml.property name="copies"
* #uml.associationEnd multiplicity="(0 -1)" inverse="media:copyManagement.Copy"
*/
#OneToMany(mappedBy="mediaRef") protected Set<Copy> copies;
public void addCopy(Copy copy) {
copies.add(copy);
}
/**
* Getter of the property <tt>copies</tt>
* #return Returns the copies.
* #uml.property name="copies"
*/
public Set<Copy> getCopies() {
return copies;
}
/**
* Setter of the property <tt>copies</tt>
* #param editionDate The copies to set.
* #uml.property name="copies"
*/
public void setCopies(Set<Copy> copies) {
this.copies = copies;
}
And this is Book class.
#Entity
#Table(name = "Book")
#NamedQuery(name = "findAllBooks", query = "select b from Book b")
public class Book extends Media {
/**
* #uml.property name="authors"
*/
#Column(name = "authors")
private ArrayList<String> authors;
/**
* Getter of the property <tt>authors</tt>
*
* #return Returns the authors.
* #uml.property name="authors"
*/
public ArrayList<String> getAuthors() {
return authors;
}
/**
* Setter of the property <tt>authors</tt>
*
* #param authors
* The authors to set.
* #uml.property name="authors"
*/
public void setAuthors(ArrayList<String> authors) {
this.authors = authors;
}
/**
* #uml.property name="isbn"
*/
#Column(name = "isbn")
private String isbn;
/**
* Getter of the property <tt>isbn</tt>
*
* #return Returns the isbn.
* #uml.property name="isbn"
*/
public String getisbn() {
return isbn;
}
/**
* Setter of the property <tt>isbn</tt>
*
* #param isbn
* The isbn to set.
* #uml.property name="isbn"
*/
public void setisbn(String isbn) {
this.isbn = isbn;
}
public Book() {
// TODO Auto-generated constructor stub
}
public Book(String title, Calendar editionDate, ArrayList<String> authors,
String isbn) throws BadParametersException {
super(title, editionDate);
this.authors = authors;
this.isbn = isbn;
// TODO Auto-generated constructor stub
}
}
Anyone can help?
If book extends media, why are you joining with the Media table? (though it would be easier with the Book and Media classes and mappings)
Querying the "Book" object should be enough. Also perhaps "MediaId" should be "mediaId". Hibernate is case sensitive on it's property names.

Categories

Resources