Erreur "Table is not mapped"
Bonjour,
Je suis nouveau développeur Spring et j'essaie de mettre en place une petite application console.
Voici mon fichier de configuration : SpringXMLConfig:
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:flow="http://www.springframework.org/schema/webflow-config"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.6.SEC01.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.6.SEC01.xsd
http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.6.SEC01.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.6.SEC01.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.6.SEC01.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-2.5.6.SEC01.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.6.SEC01.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- couches applicatives -->
<bean id="dao" class="Dao.dao" />
<bean id="service" class="Service.service">
<property name="dao" ref="dao" />
</bean>
<!-- la source de donnéees DBCP -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/gest_labo" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<!--
<property name="showSql" value="true" />
-->
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="generateDdl" value="true" />
</bean>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
<!-- Le gestionnaire de transaction -->
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- traduction des exceptions -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!-- persistence -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
</beans> |
Et voici le code de ma classe TClient:
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| package metier;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
*
* @author SYLLA
*/
@Entity
@Table(name = "t_client", catalog = "gest_labo", schema = "")
@NamedQueries({
@NamedQuery(name = "TClient.findAll", query = "SELECT t FROM TClient t"),
@NamedQuery(name = "TClient.findById", query = "SELECT t FROM TClient t WHERE t.id = :id"),
@NamedQuery(name = "TClient.findByNom", query = "SELECT t FROM TClient t WHERE t.nom = :nom"),
@NamedQuery(name = "TClient.findByDescription", query = "SELECT t FROM TClient t WHERE t.description = :description")})
public class TClient implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "Id", nullable = false)
private Integer id;
@Basic(optional = false)
@Column(name = "Nom", nullable = false, length = 255)
private String nom;
@Basic(optional = false)
@Column(name = "Description", nullable = false, length = 255)
private String description;
public TClient() {
}
public TClient(Integer id) {
this.id = id;
}
public TClient(Integer id, String nom, String description) {
this.id = id;
this.nom = nom;
this.description = description;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof TClient)) {
return false;
}
TClient other = (TClient) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "virtuaschool.metier.TClient[id=" + id + "]";
}
} |
et voici l'appel que je fais dans ma fonction main()
Code:
1 2 3 4 5
|
ApplicationContext ctx = new ClassPathXmlApplicationContext("SpringXMLConfig.xml");
// couche service
service = (IService) ctx.getBean("service");
service.getAll(); |
Et maintenant quand j'exécute mon programme le message d'erreur suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| TClient is not mapped [select p from TClient p][/quote][quote]
run:
INFO - AbstractApplicationContext.prepareRefresh(412) | Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@12a3793: display name [org.springframework.context.support.ClassPathXmlApplicationContext@12a3793]; startup date [Mon Jun 06 14:36:43 GMT 2011]; root of context hierarchy
INFO - XmlBeanDefinitionReader.loadBeanDefinitions(323) | Loading XML bean definitions from class path resource [SpringXMLConfig.xml]
INFO - AbstractApplicationContext.obtainFreshBeanFactory(427) | Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@12a3793]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1a68ef9
INFO - DriverManagerDataSource.setDriverClassName(155) | Loaded JDBC driver: com.mysql.jdbc.Driver
INFO - AbstractApplicationContext$BeanPostProcessorChecker.postProcessAfterInitialization(1197) | Bean 'dataSource' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO - AbstractApplicationContext$BeanPostProcessorChecker.postProcessAfterInitialization(1197) | Bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#b03be0' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO - AbstractApplicationContext$BeanPostProcessorChecker.postProcessAfterInitialization(1197) | Bean 'org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver#2af081' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO - LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(221) | Building JPA container EntityManagerFactory for persistence unit 'VirtuaSchoolPU'
INFO - AbstractApplicationContext$BeanPostProcessorChecker.postProcessAfterInitialization(1197) | Bean 'entityManagerFactory' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO - DefaultListableBeanFactory.preInstantiateSingletons(414) | Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1a68ef9: defining beans [dao,service,client,dataSource,entityManagerFactory,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,txManager,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0]; root of factory hierarchy
Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: TClient is not mapped [select p from TClient p]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:634)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:95) |
J'ai vraiment besoin de comprendre comment faire le mapping Spring dans le fichier de configuration.
Merci d'avance!