S
S
Sland Show2019-12-31 00:18:11
Java
Sland Show, 2019-12-31 00:18:11

Why is the entity not mapped?

There are two entities.

@Entity
@Table(name = "entry")
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class Entry {

    @Id
    @GeneratedValue
    private Long id;

    @Column(name = "entry_date")
    private Date date;

    @Column(name = "title")
    private String title;

    @Column(name = "content_id")
    @OneToOne(mappedBy = "entry", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Content content;

}


@Entity
@Table(name = "content")
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class Content {

    @Id
    @GeneratedValue
    private Long id;

    @Column(name = "content_text")
    private String content_text;

    @OneToOne
    @JoinColumn(name = "entry_id")
    private Entry entry;

}

@Bean
    CommandLineRunner runner(EntryRepository entryRepository) {
        return args -> {
            Content content = new Content();
            Entry entry = new Entry();

            content.setId(1L);
            content.setContent_text("ABC");
            content.setEntry(entry);

            entry.setId(1L);
            entry.setDate(new Date());
            entry.setTitle("DEF");
            entry.setContent(content);

            entryRepository.save(
                    entry
            );
        };
    }


I receive
@Column(s) not allowed on a @OneToOne property: com.slandshow.bank.models.Entry

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
al_gon, 2019-12-31
@al_gon

@Column -> @JoinColumn

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question