Probleme mappage : QuerySyntaxException: Author is not mapped
Bonjour,
Je suis un peu perdu. En effet, j'ai réglé mon problème précédent en changeant de système d'exploitation et j'ai continué mes opérations qui me font arriver à ceci :
Code:
org.hibernate.hql.internal.ast.QuerySyntaxException: Author is not mapped
J'ai utilisé hibernate Tools pour créer les fichiers de mapping, le fichier de configuration hibernate et le fichier reveng:
- fichier hibernate.cfg.xml:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generated 17 avr. 2018 13:54:12 by Hibernate Tools 5.2.8.Final --><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" default-access="property" default-cascade="none" default-lazy="true">
<class dynamic-insert="false" dynamic-update="false" mutable="true" name="com.catalog.Catalog.models.Author" optimistic-lock="version" polymorphism="implicit" schema="public" select-before-update="false" table="author">
<id name="authorId" type="int">
<column name="author_id"/>
<generator class="assigned"/>
</id>
<property generated="never" lazy="false" name="authorLastname" optimistic-lock="true" type="string" unique="false">
<column length="60" name="author_lastname"/>
</property>
<property generated="never" lazy="false" name="authorFirstname" optimistic-lock="true" type="string" unique="false">
<column length="60" name="author_firstname"/>
</property>
</class>
</hibernate-mapping> |
- hibernate.reveng.xml:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<table-filter match-schema="public" match-name="author"/>
<table-filter match-schema="public" match-name="book"/>
<table-filter match-schema="public" match-name="book_basket"/>
<table-filter match-schema="public" match-name="book_copy"/>
<table-filter match-schema="public" match-name="bookshelf"/>
<table-filter match-schema="public" match-name="catalog"/>
<table-filter match-schema="public" match-name="category"/>
<table-filter match-schema="public" match-name="editor"/>
<table-filter match-schema="public" match-name="library"/>
<table-filter match-schema="public" match-name="member"/>
</hibernate-reverse-engineering> |
-Author.hbm.xml:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generated 17 avr. 2018 13:54:12 by Hibernate Tools 5.2.8.Final --><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" default-access="property" default-cascade="none" default-lazy="true">
<class dynamic-insert="false" dynamic-update="false" mutable="true" name="com.catalog.Catalog.models.Author" optimistic-lock="version" polymorphism="implicit" schema="public" select-before-update="false" table="author">
<id name="authorId" type="int">
<column name="author_id"/>
<generator class="assigned"/>
</id>
<property generated="never" lazy="false" name="authorLastname" optimistic-lock="true" type="string" unique="false">
<column length="60" name="author_lastname"/>
</property>
<property generated="never" lazy="false" name="authorFirstname" optimistic-lock="true" type="string" unique="false">
<column length="60" name="author_firstname"/>
</property>
</class>
</hibernate-mapping> |
Au niveau du code java, je fais une simple opération:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
package com.catalog.Catalog.actions;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.query.Query;
import com.catalog.Catalog.models.Author;
import com.catalog.Catalog.utils.HibernateUtil;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport{
private static final long serialVersionUID = -8465571610682762828L;
private List<Author> auteur;
Session session = null;
public List<Author> getAuteur() {
return auteur;
}
public void setAuteur(List<Author> auteur) {
this.auteur = auteur;
}
public String execute() {
this.session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query<Author> authorQuery = session.createQuery("from Author");
auteur = authorQuery.list();
return SUCCESS ;
}
} |
Au niveau de HibernateUtil:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| package com.catalog.Catalog.utils;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class HibernateUtil {
private static SessionFactory sessionFactory;
public static SessionFactory getSessionFactory() {
if(sessionFactory == null) {
Configuration config = new Configuration().configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
sessionFactory = config.buildSessionFactory(serviceRegistry);
}
return sessionFactory;
}
} |
Je viens vous demander de l'aide pour savoir en quoi Author n'est pas mappé.
Je vous remercie d'avance pour votre aide.
Vinz