1

i am trying to insert data in mysql table testdata.

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;
}

}

when i am running my project it gives following exception

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

but if i remove the @Entity project runs successfully. but data is not inserting. is it possible to insert data with other methods without hibernate. if anyone have knowledge about this, i will appreciate.

1
  • consider posting full stacktrace Commented Dec 30, 2016 at 10:48

2 Answers 2

3

You don't specify the javax.persistence package for the Id annotation.

Replace

import org.springframework.data.annotation.Id;

by

import javax.persistence.Id;
Sign up to request clarification or add additional context in comments.

2 Comments

@Anupam Agnihotri great :)
@Anupam Agnihotri "Downvoter It is free ? " is not addressed to you. It is for someone who downvoted the answer without explanation. With this syntax, he receives the message :)
1

You are using a wrong @Id annotation (import org.springframework.data.annotation.Id;)

Use import javax.persistence.Id; instead

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.