> For the complete documentation index, see [llms.txt](https://admincode.gitbook.io/admincode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://admincode.gitbook.io/admincode/basics/newpage/step-1-creating-the-model.md).

# Step 1: Creating the Model

In order to effectively interact with your database, you first need to create a model that reflects the structure of your database table. This model will serve as a blueprint for the data your application handles. Here's how to create a model in a Java backend application:

1. **Identify the Database Table**: Begin by reviewing the database table you wish to represent. Make note of the fields, their data types, and any relationships with other tables.
2. **Create the Model Class**: Create a new Java class in your project that corresponds to the database table. Typically, this class will be placed inside package `model`.

```java
package com.rce.model;

import jakarta.persistence.CascadeType;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.MapsId;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.PrimaryKeyJoinColumn;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import java.util.List;
import org.hibernate.envers.AuditJoinTable;
import org.hibernate.envers.Audited;
import org.hibernate.envers.NotAudited;

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@Audited
@Entity
@Table(name="articles")
public class Article extends BaseO { 

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id
	@NotAudited
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "articles_sequence")
	@SequenceGenerator(name = "articles_sequence", sequenceName = "articles_sequence", allocationSize = 1)
	@Column(name="id", updatable = false)
	private long id;  

	@Audited(withModifiedFlag = true)
	@Column(name="title")	
	private String title;

	@Audited(withModifiedFlag = true)
	@Column(name="category")	
	private String category;

	@Audited(withModifiedFlag = true)
	@Column(name="summary")	
	private String summary;
	
	@Audited(withModifiedFlag = true)
	@JoinColumn(name = "author", referencedColumnName = "Id")
	@OneToOne(fetch = FetchType.EAGER)
	private Author author;

	@Audited
	@AuditJoinTable(name = "article_citation_aud")
	@ManyToMany(cascade=CascadeType.MERGE, fetch=FetchType.EAGER)
	@JoinTable(
			name="article_citation",
			joinColumns={@JoinColumn(name="article_id")},
			inverseJoinColumns={@JoinColumn(name="citation_id")})
	private List<Citation> citations;

	@Audited
	@AuditJoinTable(name = "articlecomments_aud")
	@OneToMany(mappedBy="article", fetch=FetchType.EAGER)
	private List<ArticleComment> comments;
	
	@Audited(withModifiedFlag = true)
	@Enumerated(EnumType.STRING)
	private ArticleTypeEnum type;
	
	@Audited
	@AuditJoinTable(name = "articletypes_aud")
	@OneToMany(mappedBy="article", fetch=FetchType.EAGER)
	private List<ArticleType> types;

	public ArticleTypeEnum getType() {
		return type;
	}

	public void setType(ArticleTypeEnum type) {
		this.type = type;
	}
	
	public List<ArticleType> getTypes() {
		return types;
	}

	public void setTypes(List<ArticleType> types) {
		this.types = types;
	}

	@Override
	public Long getId() {
		return id;
	}

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

	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category;
	}
	public String getSummary() {
		return summary;
	}
	public void setSummary(String summary) {
		this.summary = summary;
	}
	public Author getAuthor() {
		return author;
	}

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

	public List<Citation> getCitations() {
		return citations;
	}

	public void setCitations(List<Citation> citations) {
		this.citations = citations;
	}

	public List<ArticleComment> getComments() {
		return comments;
	}

	public void setComments(List<ArticleComment> comments) {
		this.comments = comments;
	}
}  
```
