wood burning stoves 2.0*
The moose likes Web Services and the fly likes Problem with Web Service Response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Problem with Web Service Response" Watch "Problem with Web Service Response" New topic
Author

Problem with Web Service Response

Abhishek Uppala
Greenhorn

Joined: May 27, 2009
Posts: 10

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

Thanks
Abhishek Uppala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Web Service Response
 
Similar Threads
Webservice for beginners
Strange ViewParams, GET Requests, AJAX behavior
No mapped data?
Exception while deleting a Entity
CascadeType.PERSIST not working