Im trying to connect postgres with a spring boot microservice app.
Have make the configuration at application.properties
# spring.application.name=item-all-service
server.port = 8081
spring.datasource.url=jdbc:postgresql://localhost:5432/xxx
spring.jpa.properties.hibernate.default_schema = public
spring.datasource.username=xxx
spring.datasource.password=xx
spring.jpa.show-sql=true
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto = update
package com.example.itemsallservice.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "T_Item")
public class ItemsModel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long itemId;
@Column(name = "nameId")
private String nameId;
public ItemsModel(long i, String nameId) {
super();
this.itemId = i;
this.nameId = nameId;
}
public ItemsModel() {}
public long getItemId() {
return itemId;
}
public void setItemId(long itemId) {
this.itemId = itemId;
}
public String getNameId() {
return nameId;
}
public void setNameId(String nameId) {
this.nameId = nameId;
}
@Override
public String toString() {
return "ItemsModel [itemId= \t " + itemId + " \t nameId=" + nameId + "] \n";
}
}
The repository class
@Repository
public interface ItemRepository extends JpaRepository<ItemsModel, Long> {
Resource class
@RestController
@RequestMapping("/item")
public class ItemResource {
@Autowired
public ItemRepository itemRepo;
@GetMapping("/all")
public String getAllEmployees() {
String result = "";
// Query query = sessionFactory.getCurrentSession().createQuery("from Employee where email = :email");
for(ItemsModel cust: itemRepo.findAll() ){
result += cust.toString() + "<br>";
}
System.out.println("itemModel" + result);
return result;
}
The result is empty
Hibernate: select itemsmodel0_.item_id as item_id1_0_, itemsmodel0_.name_id as name_id2_0_ from public.t_item itemsmodel0_
itemModel