I am using Spring Data, I have created my entities wrapped inside of an "AbstractEntity" which all objects extend to get basic columns
AbstractEntity:
@MappedSuperclass
public abstract class AbstractEntity implements Serializable{
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false)
private Date CreatedDate;
@PrePersist
protected void onCreate() {
UpdatedDate = CreatedDate = new Date();
}
...
And my Object/Entity
@Entity
public class Trade extends AbstractEntity {
When I attempt to use my repository to create a method to findByCreatedDateAfter(Date date)
I get an exception that the column can't be found...?
public interface TradeRepository extends CrudRepository<Trade, Long>{
public List<Trade> findByCreatedDateAfter(Date date);
}
It compiles (if I use certain capitolization) but than attempting to map the query, I get:
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the given name [createdDate] on this ManagedType [streaming.data.AbstractEntity]
I also would like to return the sum(amount)
of one of the amount column for this period.
The query derivation mechanism requires standard Java property naming conventions to be applied. There's no property createdDate
as it's called CreatedDate
in your class.
To customize the mapping to a certain column, use the @Column
annotation (hence the name).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With