Select File > New > Other... from the Eclipse menu.
Browse to Java > Class and click the Next button.
In the New Java Class dialog, enter the following:
The Package field: by.iba.domain
The Name field: Operation
The Interfaces list: java.io.Serializable (click the Add... button to add the interface).
NOTE: make sure Source folder is Calculator/src.
Click the Finish button.
Open the new Operation.java file and add the @Entity annotation to the class:
@Entity public class Operation implements Serializable { ...
The class is annotated with @Entity to denote that it is an Entity Object.
Add the following instance variables (future persistent fields) to the class:
private int id; private Timestamp timestamp; private double operandA; private double operandB; private String operation; private double result;
Click the Source > Generate Getters and Setters... to generate getters and setters.
Add the following annotations to the getter methods:
The getId() method is annotated with @Id to denote that id is the primary key of the entity (by default, the mapped column for the primary key of the entity is assumed to be the primary key of the primary table), the method is also annotated with @GeneratedValue to denote that the persistence provider must assign primary keys for the entity.
@Id @GeneratedValue @Column(name="OPERATION_ID") public int getId() { return id; }
@Column(name="OPERAND_A") public double getOperandA() { return operandA; }
@Column(name="OPERAND_B") public double getOperandB() { return operandB; }
@Column(length=8) public String getOperation() { return operation; }
Override the toString() method:
public String toString() { return " \n" + getTimestamp() + " : " + getOperandA() + " " + getOperation() + " " + getOperandB() + " is " + getResult(); }
Click the Ctrl + Shift + O to organize imports and Ctrl + S to save.
![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |