3

I use Spring + Hibernate with annotations and i got the following error :

org.hibernate.hql.ast.QuerySyntaxException: Produit is not mapped [from Produit]

it appens when i call this function :

public List<Produit> getListeProduit() {

    return sessionFactory.getCurrentSession().createQuery("from Produit").list();
}

This is my hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
    <mapping class="port.domain.Produit" />
</session-factory>     
</hibernate-configuration>

Produit class are annoted well with @Entity, @Table ID with @Id, @Column, @GeneratedValue The others columns with @Column

Here is my bean SessionFactory in my XXX-servlet.xml :

<bean id="sessionFactory"     class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
</bean>

EDIT : Entity Code

@Entity
@Table(name="produit")
public class Produit implements Serializable{

@Id
@Column(name="produit_id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int produitId;

@Column(name="produit_nom")
private String produitNom;

public void setProduitId(int i) {
    produitId = i;
} 

public int getProduitId() {
    return produitId;
} 

public void setProduitNom(String s) {
    produitNom = s;
} 

public String getProduitNom() {
    return produitNom;
} 
}

I know there are many threads about this problem but i don't find any correct issues. I understand that Hibernate can't mapped my class but i don't know why ...

Where could the problem come from ?

Thanks a lot.

6
  • Post the entity code please. Commented Dec 7, 2012 at 8:10
  • I add an edit to my post Commented Dec 7, 2012 at 8:15
  • Stupid question, but is the mysql instance on a Unix box or windows? Commented Dec 7, 2012 at 8:19
  • Mysql instance is on Windows Commented Dec 7, 2012 at 8:21
  • Ok, It seems like that could be an issue if my sql were on unix, stackoverflow.com/questions/10093718/… Commented Dec 7, 2012 at 8:22

1 Answer 1

3

Usually the problem is trivial: you should use javax.persistence.Entity instead of Hibernate-specific org.hibernate.annotations.Entity. The latter was deprecated in Hibernate in favour of JPA annotations where possible.

That's exactly what you didn't show, so hope it's a lucky shot :)

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

4 Comments

Oh my god ... it works finally you're right ... why org.hibernate.annotations.Entitydoesn't works ?
It was deprecated, Hibernate now uses JPA-specific annotations where possible.
So with Hibernate, i have to prefer JPA annotations instead of hibernate annotations in my entity ?
Exactly. Hibernate falls back to its own annotations when there are no analogs in JPA. Or both ways work from time to time, for such annotations processing you can find in Hibernate 'if this is JPA-specific, then this behavior. Else - that behavior'.

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.