-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: QuerySyntaxException: is not mapped [FROM
PostPosted: Fri Mar 02, 2012 4:35 pm 
Newbie

Joined: Wed May 25, 2011 3:19 pm
Posts: 7
Hello,

I working on a new project and i get an error in runtime while querying an entity.
org.hibernate.hql.ast.QuerySyntaxException: TypeSuivi is not mapped [FROM TypeSuivi as ts ORDER BY ts.nom]

I think hibernate is not communicating with mysql database
here's my files

-----------------------------------------------------------------------
Main Program

public List<TypeSuivi> listerLesTypes() throws CoteurException{
logger.info("Dans lister types");
List<TypeSuivi> liste = null;

try{
liste = new groupelti.coteur.persistence.dao.TypeSuivi().lister();
}catch(DAOException e){
logger.info(""+e.getMessage());
throw new CoteurException("...", e);
}
return liste;
}
}


-----------------------------------------------------------------------
Hibernate.cfg.xml
<hibernate-configuration>

<session-factory>

<!-- database connection setings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/expertise</property>
<property name="hibernate.connection.username">****</property>
<property name="hibernate.connection.password">****</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.charSet">utf8</property>
<property name="hibernate.connection.connectionCollation">utf8_general_ci</property>
<property name="hibernate.connection.useUnicode">false</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

<!-- Use the C3P0 connection pool. -->

<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">18000</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.validate">true</property>
<property name="hibernate.c3p0.idle_connection_test_period">300</property>
<property name="hibernate.c3p0.debug">false</property>

<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="cache.use_query_cache">false</property>
<property name="cache.use_minimal_puts">false</property>
<property name="max_fetch_depth">3</property>

<!-- sql dialect -->
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

<!-- enable hibernate s automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- echo all executed sql to std out -->
<property name="show_sql">true</property>

<mapping class="groupelti.coteur.persistence.vo.Utilisateur"/>
<mapping class="groupelti.coteur.persistence.vo.ClasseEvaluation"/>
<mapping class="groupelti.coteur.persistence.vo.EvaluationEchantillon"/>
<mapping class="groupelti.coteur.persistence.vo.GrilleEvaluation"/>
<mapping class="groupelti.coteur.persistence.vo.Nature"/>
<mapping class="groupelti.coteur.persistence.vo.Parametre"/>
<mapping class="groupelti.coteur.persistence.vo.PointEvaluation"/>
<mapping class="groupelti.coteur.persistence.vo.TypeSuivi"/>

<listener class="org.hibernate.envers.event.AuditEventListener" type="post-insert"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-update"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-delete"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="pre-collection-update"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="pre-collection-remove"/>
<listener class="org.hibernate.envers.event.AuditEventListener" type="post-collection-recreate"/>

</session-factory>

</hibernate-configuration>

-----------------------------------------------------------------------
TypeSuivi.dao

public List<groupelti.coteur.persistence.vo.TypeSuivi> lister() throws DAOException {

Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();

List<groupelti.coteur.persistence.vo.TypeSuivi> result = null;

try{
result = session.createQuery("FROM TypeSuivi as ts ORDER BY ts.nom").list();
session.getTransaction().commit();
}catch(GenericJDBCException e){
logger.info(""+e.getMessage());

session.getTransaction().rollback();
throw new DAOException("Voir log.", e);
}finally{
session.close();
}

return result;
}


-----------------------------------------------------------------------
TypeSuivi.vo

package groupelti.coteur.persistence.vo;

import java.util.Date;
import java.io.Serializable;
import java.util.Calendar;
import org.hibernate.envers.Audited;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Audited
@Table(name="type_suivi")
public class TypeSuivi implements Serializable, Comparable<TypeSuivi> {

/* attributs */

@Id
@GeneratedValue
private Integer id;

private String nom;

@Temporal(TemporalType.TIMESTAMP)
private Date date;

@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER )
@JoinColumn(name="utilisateur_id", unique = true, nullable=false)
private Utilisateur utilisateur;

/* constructeurs */

public TypeSuivi(){
date = Calendar.getInstance().getTime();
}

/* accesseurs */

public Integer getId(){return id;}
public void setId(Integer id){

// validation

if( id == null )throw new IllegalArgumentException();

// traitement

this.id=id;
}

public Date getDate(){
if( date != null ){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.getTime();
}else return null;
}

public void setDate(Date date){

// validation

if( date == null )throw new IllegalArgumentException();

// traitement

Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
this.date = calendar.getTime();
}

public Utilisateur getUtilisateur(){return utilisateur;}
public void setUtilisateur(Utilisateur utilisateur){

// validation

if( utilisateur == null )throw new IllegalArgumentException();

// traitement

this.utilisateur=utilisateur;
}

public String getNom(){return nom;}
public void setNom(String nom){

// validation

if( nom == null )throw new IllegalArgumentException();

// traitement

this.nom=nom;
}

/* comportements */

public int compareTo(TypeSuivi o1) {return this.getId().compareTo(o1.getId());}

public String toString(){return "TypeSuivi "+id;}

}

-----------------------------------------------------------------------
pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!--

Copyright (c) 2009-2010 Groupe LTI, Tous droits reserves.

Ce code source constitue de l'information confidentielle est la propriete
de Groupe LTI ("Information confidentielle"). Vous ne devez pas divulguer
cette "Information confidentielle" et son utilisation doit etre faite
en conformite avec les politiques de gestion de l'information confidentielle
et des ressources informationnelles de Groupe LTI.

-->

<modelVersion>4.0.0</modelVersion>
<groupId>groupelti</groupId>
<artifactId>coteurpersistence</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>coteurpersistence</name>
<url>http://maven.apache.org</url>

<repositories>
<repository>
<id>JBoss</id>
<name>The "public-jboss" repository group provides a combined view all JBoss community project artifacts</name>
<layout>default</layout>
<url>http://repository.jboss.org/nexus/content/groups/public-jboss</url>
</repository>
</repositories>


<dependencies>

<dependency>
<groupId>com.groupelti.sio</groupId>
<artifactId>limspersistence</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>3.6.9.Final</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.1_spec</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.9.Final</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.9.Final</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.4.GA</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>3.6.9.Final</version>
<scope>provided</scope>
</dependency>

<!-- mysql -->

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>servlet-api</artifactId>
<version>6.0.35</version>
<scope>provided</scope>
</dependency>

</dependencies>


<build>

<plugins>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${compileSource}</source>
<target>${compileSource}</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>utf8</encoding>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>

<echo message="Here I am."/>

<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>

<echo message="compile classpath: ${compile_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/>

<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.EnversHibernateToolTask" classpathref="maven.compile.classpath"/>

<hibernatetool destdir="src/main">

<classpath>
<path refid="maven.plugin.classpath"/>
<path refid="maven.compile.classpath"/>
</classpath>

<annotationconfiguration configurationfile="src/main/ressources/hibernate.cfg.xml"/>

<hbm2ddl
drop="false"
create="true"
export="true"
outputfilename="schema-coteur-post-hibernate.sql"
update="true"
delimiter=";"
format="true"/>

</hibernatetool>

</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>

<dependencies>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.9.Final</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.9.Final</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.4.GA</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>3.6.9.Final</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>3.6.9.Final</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>

</dependencies>

</plugin>





<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>

<artifactItems>

<artifactItem>
<groupId>com.groupelti.sio</groupId>
<artifactId>limspersistence</artifactId>
<type>jar</type>
</artifactItem>


</artifactItems>


<outputDirectory>${project.build.directory}/jars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>

</plugins>

<extensions>

<extension>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</extension>

</extensions>

</build>

<reporting>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<targetJdk>${compileSource}</targetJdk>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>

</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<configuration>
<onlyAnalyze>groupelti.coteur.persistence.dao.*,groupelti.coteur.persistence.gestionnaire.*,groupelti.coteur.persistence.gestionnaire.exceptions.*,groupelti.coteur.persistence.service.*,groupelti.coteur.persistence.util.*,groupelti.coteur.persistence.vo.*</onlyAnalyze>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>

</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jxr-maven-plugin</artifactId>

</plugin>

<plugin>
<artifactId>maven-surefire-report-plugin</artifactId>

</plugin>

</plugins>
</reporting>

<properties>
<compileSource>1.5</compileSource>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>


Top
 Profile  
 
 Post subject: Re: QuerySyntaxException: is not mapped [FROM
PostPosted: Mon Mar 05, 2012 2:03 pm 
Newbie

Joined: Wed May 25, 2011 3:19 pm
Posts: 7
Hey...

I found what my error was.

I wrongly named the folder containing the hibernate.cfg.xml.
"ressources" instead of "resources". Doing so the compiler now copy the hibernate.cfg.xml in the target -> classes folder of the project.

Thanks anyway.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.