Home Java JPA extending entity
Reply: 0

Java JPA extending entity

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

I have an Attachment class:

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

@Id
@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;

@ManyToOne
@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;

@Temporal(TemporalType.TIMESTAMP)
@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):

@Entity
public class AttachmentWithContent extends Attachment {

@Column(name = "FILE_CONTENT")
@Lob
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