1.org. hibernate. hql. Ast. querysyntaxexception: user is not mapped [from user] Error
Learn TodayHibernate. Deploy with myeclipse. However
Org. hibernate. hql. Ast. querysyntaxexception: user is not mapped [from user]
I checked the cause on the Internet:
1,Hibernate. cfg. XML has much less ing. Why? Because I copied them all. Not automatically generated. In addition, hibernate. cfg. xml should be placed in the root directory.
Write all the mappings you want.
<Mapping Resource = "... package name.../companyinfo. HBM. xml"/>
<Mapping Resource = "... package name.../companyinfo. HBM. xml"/>
<Mapping Resource = "... package name.../companyinfo. HBM. xml"/>
<Mapping Resource = "... package name.../companyinfo. HBM. xml"/>
<Mapping Resource = "... package name.../companyinfo. HBM. xml"/>
2. symptom:
When hql = "from person" is used, the error "person is not mapped" appears.
The configuration file is as follows:
<Hibernate-mapping>
<Class name = "src. Person"
Table = "person">
<ID name = "name"/>
<Property name = "password"/>
</Class>
</Hibernate-mapping>
Original cause:
Hql writes Po objects, not table names.
Change the class name in the red part of the configuration file.
In the second case, record it.
2.
Org. hibernate. queryexception: cocould not resolve property
In general, if an exception cannot be resolved due to the property type, the following problems may occur:
Database fields and persistent class ing files, and the attribute names or types in persistent class files may not match;
The attribute type in the persistent class ing file may be faulty. For example, if the Java type is used, use uppercase letters (for example, type = "Java. lang. string "), if the hibernate type is used, use lower case (such as type =" string ").
3.Illegal attempt to dereference collection
From department as d Where D. Employees. Name = 'Tom ';
Exception during running: org. hibernate. queryexception: illegal attempt to dereference collection
In the preceding hql statement, department's associated entity employees is a set instead of an employee entity.
In versions earlier than hibernate3.2.2, Hibernate automatically uses implicit inner join for correlated entities,
That is to say, the following SQL statement does not have any problems: from department as d Where D. Employees. Name = 'Tom ';
Since hibernate3.2.3, Hibernate has changed this implicit inner join strategy.
For the following statement:
From department as d Where D. Employees. Name = 'Tom ';
If employees is a common component attribute or a single correlated entity, Hibernate automatically generates an implicit inner join.
If myevents is a collection, sorry! The Org. hibernate. queryexception: illegal attempt to dereference collection exception will occur.
According to hibernate official statement:
This makes the implicit association more deterministic (Original: This makes implicit joins more deterministic ).
It is recommended to write as follows:
From department as D inner join fetch D. Employees e where E. Name = 'Tom ';