Today, when I was working on a project, I used HQL to look up the database, but all the returned results were null. Note that the returned list is not null, but there are values in the list. The size of the list is the total number of records, but when I traverse the list output, all the elements in the list are null. I suspect that there is something wrong with my conditions. I have removed all the conditions, leaving only one sentence:
String hql = "from CarMaintain t";
It’s worth the rest of the sentence, but it’s still the result. I searched the information on the Internet, and all of them were wrong answers. Without exception, I said it was impossible… Then how did I meet… Others are unreliable, so we have to find our own problems.
I began to analyze, why only this sentence has this situation, and other sentences are OK?I found that the table in question has no primary key. Yes, that’s the reason. When there is no primary key, hibernate’s reverse engineering will automatically construct a composite primary key for us, so I started to check hbm.xml The file and configuration are correct. What’s the problem?I collapsed all afternoon for it. The reason is due to the internal mechanism of hibernate,
In my table without primary key, the fields in the composite primary key constructed by hibernate have null values, so no matter how you look it up, it is null in the end. When you break the point, you will see [null, null, null,….]
resolvent:
1. Create a new field, use it as the primary key, and hbm.xml The file is modified correctly
2. All fields contained in the composite primary key cannot be null in the database
It took a long time to solve this problem. I hope I can help you.
Read More:
- nested exception is org.hibernate.PropertyAccessException: Null value was assigned to a property
- Use of HQL query.list () is a null pointer exception, but the database can find out the result
- AVD FFmpeg avcodec_ A solution of open2 returning – 1 (operation not permitted)
- org.springframework.orm . hibernate3. Hibernatequeryexception: XXX is not mapped solution
- Solution of Greenplum query calling function error
- LeetCode 23. Merge k Sorted Lists(java)
- org.hibernate.MappingException: invalid override definition
- 21. Merge Two Sorted Lists [easy] (Python)
- org.apache.ibatis.type.TypeException: Error setting non null for parameter #4 with JdbcType null
- How to call stored procedure in Hibernate
- Reading package lists… Error! (How to Fix)
- SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
- Solution to the problem that SQL database query result field contains new line character, which leads to copy to excel dislocation
- Solution to null pointer error in array
- Run with Python console solution is set by default for all projects in pcharm
- Table ‘sell.hibernate_sequence‘ doesn‘t exist
- “No nodes available to run query” is reported when using Presto to connect to MySQL query“
- MySQL Workbench: Error Code: 2013. Lost connection to MySQL server during query solution
- Error:null value in entry: incrementalFolder=null
- NPM can’t find D: //nodejs/node all of The solution of sudden_modules/NPM/bin/npm-cli.js