Home Java JPA extending entity
Reply: 0

Java JPA extending entity

user4589 Published in September 20, 2018, 12:43 pm

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.

share|improve this question

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO