Home Java JPA extending entity
Reply: 0

Java JPA extending entity

user1477 Published in June 23, 2018, 4:24 am

I have an Attachment class:

@Table(name = "ATTACHMENT")
public class Attachment implements Serializable {

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_gen")
@SequenceGenerator(name = "seq_gen", sequenceName = "attachment_seq", allocationSize = 1)
@Column(name = "ATTACHMENT_ID", nullable = false)
private Long id;

@JoinColumn(name = "CREATED_BY", nullable = false)
private User createdBy;

@Column(name = "FILE_NAME", nullable = false)
private String fileName;

@Column(name = "CONTENT_TYPE", length = 100, nullable = false)
private String contentType;

@Column(name = "CREATE_DATE", nullable = false)
private Date createDate;

and I want to extend this class with one additional field (which is on this table too):

public class AttachmentWithContent extends Attachment {

@Column(name = "FILE_CONTENT")
private byte[] fileContent;

And then I want to query that using JpaRepository:

 List<AttachmentWithContent> findByIdIn(List<Long> attachmentsIds);

but there's an error

'Attachment' domain type or valid projection interface expected here.

I need to be able to query Attachment class one time, and AttachmentWithContent another time.

I've tried with @Inheritance and @MappedSuperClass, but it doesn't work.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.330056 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO