Search code examples
javaoracle-databaserestcdibackend

Java backend RESTful server application with CDI


My task is to create a JavaEE application with RESTful services using CDI. I would have to get the data from an Oracle database.

I have researched on the internet on how to make this, but I just couldn't find a project/guide which was using all that I needed. I have created an entity class, but I can't figure out how to deal with the data from the database, just crud for the database.

My entity class:

 @Entity
@Table(name = "BOOKS")
public class Book implements Serializable {

    private int id;
    private String author;
    private String title;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name = "author", unique = true, nullable = false)
    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author= author;
    }

    @Column(name = "title", unique = true, nullable = false)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title= title;
    }

}

Any help, or link to guides is very appreciated. Thanks in advance!


Solution

  • What you are looking for is a tutorial that combines JPA with jdbc. Let the jpa handle all the talking to the database, you can focus on developing. I suggest using spring.

    Here is an example that uses Spring.

    This is an example using Eclipse-link.

    This is how you connect to an oracle database.

    This is a great tutorial that cobers the whole shebang from scratch to adding and reading from your db.