I am new to Hibernate.
I want to get all the records from the transaction table,
I got the following error
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column transactio2_.deleted' in 'field list'
Although the column deletedis presented in the table
Entity Class:
@Entity
@Table(name = "transaction")
public class Transaction implements Comparable<Transaction>
{
@Id
@GeneratedValue
@Column(name = "transactionId")
private int transactionId;
@Column(name = "date")
private Date date;
@Column(name = "amount")
private BigDecimal amount;
@ManyToOne
@JoinColumn(name = "transactionTypeId")
private TransactionType transactionType;
@ManyToOne
@JoinColumn(name = "userId")
private User user;
@Column(name = "operation")
private String operation;
@Column(name = "lastUpdate")
private Date lastUpdate;
@Column(name = "deleted")
private int deleted;
@Column(name = "remark")
private String remark;
public Transaction()
{
super();
}
@Override
public int compareTo(Transaction c)
{
if (getTransactionId() < c.getTransactionId())
{
return -1;
}
if (getTransactionId() > c.getTransactionId())
{
return 1;
}
return 0;
}
public Date getLastUpdate()
{
return lastUpdate;
}
public void setLastUpdate(Date lastUpdate)
{
this.lastUpdate = lastUpdate;
}
public User getUser()
{
return user;
}
public void setUser(User user)
{
this.user = user;
}
public int getDeleted()
{
return deleted;
}
public void setDeleted(int deleted)
{
this.deleted = deleted;
}
public int getTransactionId()
{
return transactionId;
}
public void setTransactionId(int transactionId)
{
this.transactionId = transactionId;
}
public Date getDate()
{
return date;
}
public void setDate(Date date)
{
this.date = date;
}
public BigDecimal getAmount()
{
return amount;
}
public void setAmount(BigDecimal amount)
{
this.amount = amount;
}
public TransactionType getTransactionType()
{
return transactionType;
}
public void setTransactionType(TransactionType transactionType)
{
this.transactionType = transactionType;
}
public String getOperation()
{
return operation;
}
public String getRemark()
{
return remark;
}
public void setRemark(String remark)
{
this.remark = remark;
}
public void setOperation(String operation)
{
this.operation = operation;
}
}
Sleep failure
@ManagedBean
@ViewScoped
public class TransactionBean implements Serializable
{
ArrayList<Transaction> transactionList = new ArrayList<>();
public TransactionBean()
{
Session session = HibernateUtil.getSessionFactory().openSession();
@SuppressWarnings("unchecked")
transactionList = (ArrayList<Transaction>) session.createCriteria(Transaction.class).list();
}
What is wrong in my code?
Edit: here is the DB table creation instruction
delimiter $$
CREATE TABLE `transaction` (
`transactionId` int(11) NOT NULL AUTO_INCREMENT,
`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`amount` decimal(10,2) DEFAULT NULL,
`transactionTypeId` int(11) NOT NULL,
`operation` varchar(45) DEFAULT NULL,
`lastUpdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`userId` int(11) NOT NULL,
`deleted` tinyint(4) NOT NULL DEFAULT '0',
`remark` varchar(450) DEFAULT NULL,
PRIMARY KEY (`transactionId`),
KEY `fk_transaction_1` (`userId`),
KEY `fk_transaction_2` (`transactionTypeId`),
CONSTRAINT `fk_transaction_1` FOREIGN KEY (`userId`) REFERENCES `user` (`userId`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_transaction_2` FOREIGN KEY (`transactionTypeId`) REFERENCES `transaction_type` (`transactionTypeId`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=latin1$$
source
share