2016-02-24 27 views
3

我有這樣的例外:hibernate.MappingException持久化類不知道

org.hibernate.MappingException:持久化類的不知道: java.lang.Long中

我使用Hibernate 5.1 .0.Final和彈簧ORM 4.2.4.RELEASE

我的彈簧配置文件(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"> 
    <property name="sessionFactory" ref="hibernateAnnotatedSessionFactory" /> 
</bean> 

而且我有兩個MySQL表,UserAddress

User = Id, Name and Firstname 
Address = Id, Street, City and UserId 

的用戶ID在我的地址EntityBean的,我這樣做:

@OneToOne 
@JoinColumn(name="id") 
public Long getIdUtilisateur() { 
    return idUtilisateur; 
} 

回答

6

不能使用非實體作爲OneToOneJoinColumn的目標,因爲你在這裏做:

@OneToOne 
@JoinColumn(name="id") 
public Long getIdUtilisateur() { 
    return idUtilisateur; 
} 

相反,您可以使用這種方法來映射UtilisateurAddress r elationship:

@OneToOne 
@JoinColumn(name="id") 
public Utilisateur getUtilisateur() { 
    return utilisateur; 
} 

當然,Utilisateur應該是一個實體:

@Entity 
public class Utilisateur { ... } 
+0

哦!我明白 !我會嘗試。謝謝 ! – Paladice