1

I have three classes corresponding to three tables in mysql database. My classes are as follows.

@Entity
@Table(name="location")
public class Location {

    private Integer locationId;
    private Integer hospitalId;
    private Integer regionId;
    private String locationCode;
    private String locationName;
    private String locationType;


@Entity
@Table(name="hospital_region")
public class HospitalRegion {


    private Integer regionId;
    private Integer hospitalId;
    private String regionCode;
    private String regionName;
    public enum Status{Active,Inactive}
    private Status status;


@Entity
@JsonAutoDetect
@Table(name="hospital_information")
public class HospitalInformation{


    private Integer hospitalId;
    private String shortName;
    private String name;
    private Integer packageId;
    private Date implementationDate;
    private Date validFrom;
    private Date validUpTo;
    private Date lastUpload;
    public enum SubscriptionType{Free,Complimentary,Paid}
    private Integer totalUsers;

I am making a Web Services for a Hospital Application where one region could have multiple locations(one-to-many) and one hospital could be in multiple regions(one-to-many).

So what I want to do is make a web service that would insert the data into location table.The ideal workflow should be that I shall pass every field in Location class as a json object to insert a record into the Location table.

My Business Logic should first check for my regionId and hospitalId value passed in the json object . If the hospitalId which is passed corresponds to the value of regionId in region table, if both correspond, only then data should be saved.

So I need help about how to implement it as a Business Logic.Thanks in advance

Abhishek Ghosh
  • 2,593
  • 3
  • 27
  • 60
Dilpreet
  • 61
  • 1
  • 7
  • 1
    Start by reading about JPA and associations, since you obviously missed that part. Then try implementing it by yourself. Then if you have a concrete problem, come back here and ask a question. "I need help" is not a question. – JB Nizet Apr 20 '15 at 06:09
  • I am sure its not a question. But Its what everybody here needs. So P.S i need advise/help/solution to this question. – Dilpreet Apr 20 '15 at 06:17
  • I think you should change title of your question....it is misguiding other SO user what you really want to ask!!! btw have you performed any example of Spring +Hibernate example yet??? – Dev Apr 20 '15 at 08:24

1 Answers1

0

You miss the JPA relationships concept.

Your attributes are not annotated in the 3 classes.


You need to read about:

  • @ManyToOne Relation
  • @OneToMany Relation
  • @OneToOne Relation
  • @ManyToMany Relation



See more:

JPA Foreign Key Annotation

JPA Relationships 1

JPA Relationships 2

Community
  • 1
  • 1
antoniodvr
  • 1,259
  • 1
  • 14
  • 15