Posts

Showing posts with the label Hibernate

Can Someone Explain MappedBy In JPA And Hibernate?

Answer : MappedBy signals hibernate that the key for the relationship is on the other side. This means that although you link 2 tables together, only 1 of those tables has a foreign key constraint to the other one. MappedBy allows you to still link from the table not containing the constraint to the other table. By specifying the @JoinColumn on both models you don't have a two way relationship. You have two one way relationships, and a very confusing mapping of it at that. You're telling both models that they "own" the IDAIRLINE column. Really only one of them actually should! The 'normal' thing is to take the @JoinColumn off of the @OneToMany side entirely, and instead add mappedBy to the @OneToMany . @OneToMany(cascade = CascadeType.ALL, mappedBy="airline") public Set<AirlineFlight> getAirlineFlights() { return airlineFlights; } That tells Hibernate "Go look over on the bean property named 'airline' on the th...

Any Idea On H2 (Oracle MODE) "Syntax Error : SELECT NEXTVAL FROM[*] DUAL"?

Answer : Please ensure the sequence is created. If it is created, then it works for me: create sequence SQ_PERSON_ID; select SQ_PERSON_ID.nextval from dual; If it is not created, then the same error message is thrown as you got. I was working on h2 with Oracle mode but all the above solutions mentioned above didn't work for me. Although after some research I found that this query will work fine for fetching the next value in the sequence. select nextval('SchemaName', 'SequenceName') ; Check if you use the same schema under which the sequence is created. If not, insert a schema prefix before sequence name, such is MYUSER.MY_SEQ.