SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:If you have an id field only, you do not have a JPA relationship. There may be a relationship on a database level, but JPA needs entities, not ids.
Himai Minh wrote:Tangara,
First of all, you need @Id for the orderId.
Secondly, you may need something like this:
@OneToOne
private Pet pet;
In this way, the JPA will set a feign key for the Pet.
Reference:
https://www.baeldung.com/jpa-entities
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Himai Minh wrote:Hi, Tangara,
I think you can omit @PrimaryKeyJoinColumn.
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: model.Order column: pet_id (should be mapped with insert="false" update="false"
Rob Spoor wrote:Why not just use order.getPet().getId()?
Himai Minh wrote:Hi, Tangara,
I think you can omit @PrimaryKeyJoinColumn.
Himai Minh wrote:Hi, Tangara,
You may find this tutorial helpful https://www.baeldung.com/jpa-persisting-enums-in-jpa
You may need to annotate the field by @Enumerated(EnumType.String).
Himai Minh wrote:The fields in your Pet class will be mapped to the database table as Pet is annotated with @Entity.
Do you get a chance to see the table generated ?
Himai Minh wrote:@OneToOne can be uni-directional or bidirectional.
If the @OneToOne is uni-directional, it is in one class. That class is the owner.
If it is bidirectional, it is in two classes. One class is the owner. The other one is being owned.
The owner has a feign key refering to the being owned entity.
I highly recommend this book :
https://www.amazon.com/Pro-JPA-Mastering-Persistence-Technology/dp/1430219564/ref=sr_1_3?dchild=1&keywords=JPA+Pro&qid=1610031880&sr=8-3
Himai Minh wrote:Is your PetStatus saved to the Pet table?
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |