i am passing a model class object but it print ad normal object

46 views Asked by At

i am passing hibernate model class object type list but it prints as [Ljava.lang.Object;@1ec3adc.i am using spring mvc and tile hibernate.i want to pass "Subtab" type list.but it's passing "object" type list.

here's the code for returning the list :

DAOImpl :

public List<Subtab> listSubtab(int usertype){
        List<Subtab> subtablist=sessionFactory.getCurrentSession().createQuery("SELECT s.maintab, s.description, s.ref from Subtab s,Authintication a where  s.subtabId = a.subtab and a.usertype = '" + usertype + "'")
                .list();

        return subtablist;


    }

controller :

List<Subtab> subtablist=(List<Subtab>)loginService.listSubtab(userExists);
 model.addAttribute("SubtabsList",subtablist);

daO:

public List<Subtab> listSubtab(int usertype);   

service :

public List<Subtab> listSubtab(int usertype);

serviceImpl :

 @Transactional
  public List<Subtab> listSubtab(int usertype) {

      return loginDAO.listSubtab(usertype);
  }
jsp:

<c:if test="${not empty SubtabsList}">
   <c:forEach var="ob"  items="${SubtabsList}">

    <p>${ob}</p>

   </c:forEach>

</c:if>
1

There are 1 answers

0
codedabbler On BEST ANSWER

Please go through the Hibernate documentation: https://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/queryhql.html

Queries can return multiple objects and/or properties as an array of type Object[]

If you would like to return Subtab objects then change your query to

SELECT s FROM Subtab s ...

Also please use bind variables in your query as you will avoid a lot of pitfalls in the future.