• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with Web Service Response

 
Greenhorn
Posts: 10
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to developing Web Services and have run into a problem with my web service. I have a web service exposed using Aegis mapping. The service implementation calls business logic which uses Hibernate to retrieve a record from DB. All is working fine from Hibernate implementation but when the web service is returning the response, the getter() on the object is being called recursively. Kindly help if I am doing something wrong.

Here is the code snippet

public Interface ItemService(){
public Item getItemList();
}

public class ItemServiceImpl() implements ItemService{
public Item getItemList(){
return ItemServiceManager.getItems();
}
}

public class ItemServiceManager(){
public static Item getItems(){
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
session.load(Item.class,1L);
transaction.commit();
session.close();
}
}

@Entity(name="tb_Item")
public class Item {

@Id
@Column(name = "Id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "ItemName")
private String itemName;
@Column(name = "ItemCategory")
private String itemCategory;

@OneToMany(mappedBy="item")
private Set<OrderItem> orderItems;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getItemName() {
return itemName;
}

public void setItemName(String itemName) {
this.itemName = itemName;
}

public String getItemCategory() {
return itemCategory;
}

public void setItemCategory(String itemCategory) {
this.itemCategory = itemCategory;
}

public Set<OrderItem> getOrderItems() {
return orderItems;
}

public void setOrderItems(Set<OrderItem> orderItems) {
this.orderItems = orderItems;
}

}

@Entity(name="tb_OrderItem")
public class OrderItem {

@Id
@Column(name = "OrderItemId")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long orderItemId;
@ManyToOne
@JoinColumn(name = "OrderId")
private Order order;

@ManyToOne
@JoinColumn(name = "ItemId")
private Item item;

public Long getOrderItemId() {
return orderItemId;
}

public void setOrderItemId(Long orderItemId) {
this.orderItemId = orderItemId;
}

public Order getOrder() {
return order;
}

public void setOrder(Order order) {
this.order = order;
}

public Item getItem() {
return item;
}

public void setItem(Item item) {
this.item = item;
}
}


On debugging, I observed that getOrderItems() in Item class and getItem() in OrderItem class are called recursively


Kindly help

Thanks
Abhishek
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic