0

With the following mapping file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="net.woodenstar.model.shopcenter.GroupItem" table="GROUP_ITEMS">
    <id name="id" type="int">
        <column name="SHC_GIT_ID" />
        <generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
            <param name="sequence_name">GROUP_ITEMS_SEQUENCE</param>
            <param name="optimizer">none</param>
            <param name="increment_size">1</param>
        </generator>
    </id>
    <property name="name" type="string">
        <column name="SHC_GIT_NAME" length="30" unique="false" not-null="true" />
    </property>
</class>

the model GroupItem is being saved without any hesitation, but when it comes to:

List<GroupItem> result = query.list();

the result is a list with the members of null. The dbms is mysql.

UPDATE ONE

the query:

from net.woodenstar.model.shopcenter.GroupItem e  where 1=1  order by e.id

enter image description here

4
  • you dont get any errros? Commented Jul 3, 2016 at 11:27
  • @YoucefLaidani no, Not errors. Commented Jul 3, 2016 at 11:28
  • can you show us your query? Commented Jul 3, 2016 at 11:29
  • @YoucefLaidani please read the update. Commented Jul 3, 2016 at 11:31

1 Answer 1

1

What you're looking at is the internal structure of an empty ArrayList. Look at the size. It's 0. This is not a list of nulls. It's an empty list. The list is backed by an array, and since the list is empty, all the elements of the backing array are null.

So, the result you get is perfectly normal: the query just didn't find any matching entity.

Sign up to request clarification or add additional context in comments.

5 Comments

Well, but there is entities on database and every time I run the sql generated by hibernate in console logs directly in mysql, the results just acquired.
Then either all this data is not committed yet, or your Hibernate app doesn't connect to the same database/schema as the one you use to look at your table.
None of the above. saving the entities in database is via application itself. having seen the database with it's own interface (phpMyAdmin) shows committed data.
Your screenshot shows that you're not looking at the result of query.list(), which is an ArrayList. You're looking at The field entityList of a class named QueryResult. I have no idea what that is. Just do List<GroupItem> result = query.list(); System.out.println(result);.
@JB-Nizet List list = qry.list() is returning a list of size 1 with null values. And list==null and list.isEmpty() both returns false. Why ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.