2016-03-21 20 views
0

Projemle ilgili bir sorunum var. i mvn jetty:run sonra aşağıdaki hata oluştuğunda: BuradaHata: org.hibernate.property.access.spi.PropertyAccessBuildingException, Nasıl düzeltilir?

Caused by: org.springframework.beans.factory.BeanCreationException: Error creati ng bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/ userservice-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.property.access.spi.PropertyAccessBuildingException: Could not loc ate field nor getter method for property named [edu.java.spring.service.user.mod el.User#username]

dosya userservice-servlet.xml İşte

<beans 
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.0.xsd "> 
    <context:component-scan base-package="edu.java.spring.service.user.controller"></context:component-scan> 
    <context:component-scan base-package="edu.java.spring.service.user.dao"></context:component-scan> 
    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 

     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop> 
       <prop key="hibernate.show_sql">true</prop> 
      </props> 

     </property> 
     <property name="mappingLocations"> 
      <list> 
       <value>classpath:User.hbm.xml</value> 
      </list> 
     </property> 

     <property name="packagesToScan" value="edu.java.spring.service.user.model" /> 
    </bean> 
    <bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" /> 
     <property name="url" 
      value="jdbc:derby:D:\PROJECTSPRING\userdb;create=true" /> 
     <property name="username" value="" /> 
     <property name="password" value="" /> 
    </bean> 
</beans> 

İşte

package edu.java.spring.service.user.model; 

import java.util.Date; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.EnumType; 
import javax.persistence.Enumerated; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.Table; 
import javax.persistence.UniqueConstraint; 
@Entity 
//@Table(name = "user",uniqueConstraints={@UniqueConstraint(columnNames="username")}) 
public class User { 
// @Column(name = "gender", nullable = false) 
// @Enumerated(EnumType.STRING) 
    public Gender getGender() { 
     return gender; 
    } 
    public void setGender(Gender gender) { 
     this.gender = gender; 
    } 
// @Id 
// @GeneratedValue(strategy = GenerationType.IDENTITY) 
// @Column(name = "username", unique = true, nullable = false) 
    public String getUserName() { 
     return userName; 
    } 
    public void setUserName(String userName) { 
     this.userName = userName; 
    } 
// @Column(name = "password", nullable = false) 
    public String getPassWord() { 
     return passWord; 
    } 
    public void setPassWord(String passWord) { 
     this.passWord = passWord; 
    } 
// @Column(name = "birthday", nullable = false) 
    public Date getBirthDay() { 
     return birthDay; 
    } 

    public void setBirthDay(Date birthDay) { 
     this.birthDay = birthDay; 
    } 
// @Column(name="age", nullable = false) 
    public Integer getAge() { 
     return age; 
    } 
    public void setAge(Integer age) { 
     this.age = age; 
    } 
    private String userName; 
    private String passWord; 
    private Date birthDay; 
    private Integer age; 
    private Gender gender; 


} 

User.hbm.xml

dosya User.java dosyası
?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<hibernate-mapping> 
    <class name="edu.java.spring.service.user.model.User" table="user"> 
     <id name="username" column="username"/> 
     <property name="password" column="password"/> 
     <property name="birthday" type="date" column="birthday"/> 
     <property name="age" type="number" column="age"/> 
     <property name="gender" column="gender" /> 

    </class> 
</hibernate-mapping> 
+0

yerine getUsername() ve setUsername() yöntemlerini bulmayı bekliyor. Lütfen, 'User.hbm.xml' ve tam yığın izlemesi ekleyin. –

+0

@ v.ladynev Mesajımdaki User.hbm.xml dosyasını düzenliyorum –

cevap

1

User.hbm.xml dosyanız, özellik kullanıcı adı (tüm lowecase) belirtiyor ve Kullanıcı sınıfınızın bir userName özelliği var (deve durumda). Hazırda bekletme, getUserName() ve setUserName()

İlgili konular