2016-12-30 14 views
1

Я пытаюсь вставить данные в таблицу mysql testdata.spring, hibernate: проблема с созданием новой модели @Entity

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.Table; 


import org.springframework.data.annotation.Id; 


import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.Table; 


import org.springframework.data.annotation.Id; 

@Entity 
@Table(name = "testdata") 
public class testdata { 


    @Id 
    @Column(name = "image_id") 
    private String image_id; 


    @Column(name = "post_id") 
    String post_id; 

    @Column(name = "image") 
    String image; 

    public String getPost_id() { 
     return post_id; 
    } 

    public void setPost_id(String post_id) { 
     this.post_id = post_id; 
    } 

    public String getImage() { 
     return image; 
    } 

    public void setImage(String image) { 
     this.image = image; 
    } 

    public String getImage_id() { 
     return image_id; 
    } 

    public void setImage_id(String image_id) { 
     this.image_id = image_id; 
    } 

    public testdata(String post_id, String image, String image_id) { 
     super(); 
     this.post_id = post_id; 
     this.image = image; 
     this.image_id = image_id; 
    } 

} 

public String getPost_id() { 
    return post_id; 
} 

public void setPost_id(String post_id) { 
    this.post_id = post_id; 
} 

public String getImage() { 
    return image; 
} 

public void setImage(String image) { 
    this.image = image; 
} 

public String getImage_id() { 
    return image_id; 
} 

public void setImage_id(String image_id) { 
    this.image_id = image_id; 
} 

public testdata(String post_id, String image, String image_id) { 
    super(); 
    this.post_id = post_id; 
    this.image = image; 
    this.image_id = image_id; 
} 

}

, когда я бегу мой проект дает следующее исключение

springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.demo.service.ServiceInterface com.demo.controller.UserController.service; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.demo.dao.UserDao com.demo.service.ServiceImpl.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.demo.dao.UserDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in com.demo.conf.HibernateConfiguration: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.demo.model.testdata 

но если я удалить проект @Entity проходит успешно. но данные не вставляются. можно вставить данные другими способами без спящего режима. если у кого есть знания об этом, я буду признателен.

+0

рассмотреть размещение полной StackTrace –

ответ

3

Вы не указываете javax.persistence пакет для Id аннотацию.

Заменить

import org.springframework.data.annotation.Id; 

по

import javax.persistence.Id; 
+0

сделано. оно работает. –

+0

@Downvoter Это бесплатно? – davidxxx

+0

@Anupam Agnihotri отлично :) – davidxxx

1

Вы используете неправильно@Id аннотацию (import org.springframework.data.annotation.Id;)

Используйте import javax.persistence.Id; вместо

 Смежные вопросы

  • Нет связанных вопросов^_^