我有这个例外:
org.hibernate.MappingException:未知的持久化类:java.lang.Long
我正在使用Hibernate 5.1.0.Final和spring-orm 4.2.4.RELEASE
我的spring配置文件(spring.xml):
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/ecollection" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="hibernateAnnotatedSessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.ecollection.model.Adresse</value>
<value>com.ecollection.model.Utilisateur</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<bean id="utilisateurDao" class="com.ecollection.dao.UtilisateurDaoImpl">
<property name="sessionFactory" ref="hibernateAnnotatedSessionFactory" />
</bean>
<bean id="adresseDao" class="com.ecollection.dao.AdresseDaoImpl"> …Run Code Online (Sandbox Code Playgroud) 我有一些桌子:
PROFIL:id_profil,...
体验:id_experience,id_profil#,...
COMPETENCE_LEVEL:id_competence_level,级别,...
一个PROFIL可以具有很多经验和COMPETENCE_LEVEL。
一个经验可以有很多COMPETENCE_LEVEL。
一个COMPETENCE_LEVEL涉及到很多经验。
因此,对我而言,这是EXPERIENCE和COMPETENCE_LEVEL之间的(np)ManyToMany关系。
我试过了:
PROFIL.java:
@Entity
@Table(name="profil")
public class Profil {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id_profil")
private Long idProfil;
public Profil() {
super();
}
public Long getIdProfil() {
return idProfil;
}
public void setIdProfil(Long idProfil) {
this.idProfil = idProfil;
}
@Override
public String toString() {
//[...]
}
}
Run Code Online (Sandbox Code Playgroud)
EXPERIENCE.java:
@Entity
@Table(name="experience")
public class Experience {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id_experience") …Run Code Online (Sandbox Code Playgroud)