how to design your own customise repository in Java springboot for micro services Get Api which will take one or n number of parameter define in request object
For eg: search/user?will give all user details search/user?name=john will give data only have name with have john Search/user?name=john&salary=100 will give specific data to name and salary search/user?name=john&salary=100&add=china will give specific record to name salary and address
Same way the this one Url search/user will take one or n number of define request object in it so that this single Api will give output json objects as per the inputs provided
below is my code and the error i am getting in joining a query
Mobile Entity:
@Entity
@Table(name = "MOBILE")
public class Mobile implements Serializable {
//Logger logger = (Logger) LoggerFactory.getLogger(Mobile.class);
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "brand")
private String brand;
@Column(name = "phone")
private String phone;
@Column(name = "picture")
private String picture;
@Column(name = "sim")
private String sim;
@Column(name = "resolution")
private String resolution;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name ="hardware_id",referencedColumnName = "id")
private Hardware hardware;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="releases_id",referencedColumnName = "id")
private Releases releases;
Hardware Entity
@Entity
@Table(name="Hardware")
public class Hardware implements Serializable {
//Logger logger = (Logger) LoggerFactory.getLogger(Hardware.class);
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name="audioJacks")
private String audioJacks;
@Column(name = "gps")
private String gps;
@Column(name = "battery")
private String battery;
enter code here
Releases Entity class
enter code here
@Entity
@Table(name="Releases")
public class Releases implements Serializable {
//Logger logger = (Logger) LoggerFactory.getLogger(Releases.class);
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name="priceEuro")
private long priceEuro;
@Column(name="announceDate")
private String announceDate;
Repoimplementation
@Repository
@Transactional(readOnly = true)
public class UserRepositoryCustomizedImpl implements UserRepoCustom {
@PersistenceContext
EntityManager entityManager;
@Override
public List<UserInformation> search(Map<String, String> requestMap) {
if(requestMap!=null && requestMap.isEmpty()) {
}
//Below commented all the query i tried i got the error for all it is query which is wrong i am writing help me with the write query :)
//String qry="Select m.brand,m.phone,m.picture,h.audioJacks,h.gps from
com.example.users.m.hardware_id.Mobile m inner join
com.example.users.entities.Hardware h where m.hardware_id=h.id ";
//SELECT DISTINCT e FROM Employee e INNER JOIN e.tasks t
//String qry="select m from Mobile m inner join m.hardware h";
String qry="Select m.brand from Mobile m inner join m.hardware_id h
where h.id=m.hardware_id";
System.out.println("Query is "+ qry);
Query query = entityManager.createQuery(qry,Hardware.class);
return query.getResultList();
}
}
String qry="Select m.brand from Mobile m inner join m.hardware_id h where h.id=m.hardware_id";
You are referring to hardware_id
as the join property (assuming it as the join column name)
You should instead use the property name of the attribute in the Entity class. ie hardware
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.