Questions tagged [hibernate-onetomany]

Questions regarding the implementation of one to many relations using Hibernate ORM framework

281 questions
2
votes
2 answers

Hibernate Table per Subclass approach - mappedBy reference an unknown target entity property

I have a table hierarchy like Job{jobId, title} with One to Many relation with Task{taskId, jobId(FK), task_title} with One to Many relation with SubTask{subTaskId, TaskId(FK), subtask_title}. Now I have a subset of tables which extend these…
Adithya Puram
  • 303
  • 2
  • 6
  • 23
2
votes
1 answer

How can i add duplicate items to an entity which is mapped(OneToMany) to another entity class while using spring mvc and Hibernate

I have an entity "user" which is OneToMany mapped to another entity "item". List of Items are successfully added until the items are not duplicate. How can add duplicate items to the user. In User entity @OneToMany(mappedBy="user") private…
2
votes
1 answer

Unidirectional OneToMany with Foreign key doesn't insert to table

I have the following classes: @Entity @Table(name = "PARENT") public class Parent { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "PARENT_ID", unique = true, nullable = false, insertable = true, updatable = true) private Long…
Shvalb
  • 1,835
  • 2
  • 30
  • 60
2
votes
2 answers

Is it possible for Hibernate to fetch two levels of sets with one select?

I have three entities: @Entity @Table(name="a") class A { @Id Long id; @OneToMany(fetch = FetchType.EAGER) @JoinColumn(name = "a_id") Set bs; // ... other fields } @Entity @Table(name = "b") class B { @Id Long id; …
Patryk Dobrowolski
  • 1,565
  • 2
  • 13
  • 29
2
votes
1 answer

Hibernate OneToMany OrderBy messes up main query

I have a class Video that I'm querying for in my Hibernate and I am ordering the results by Order.desc("id"). The query works as expected. However, if I add a @OneToMany annotation in Video to include the comments, I also add an @OrderBy to that…
1
vote
1 answer

Hibernate. How to properly organize relation a one-to-many with annotations?

I am trying to make a simple example of Hibernate. I have two entities: User and Note. They have relation a one to many (one user can have a lot of notes). Please help me to correctly display these relationships in a database using annotations.But I…
Michael
  • 1,152
  • 6
  • 19
  • 36
1
vote
0 answers

Hibernate Cascade operation on OneToMany relation gives update query

@Entity @Table(name="table1") public class Parent{ @Id @Column(name="Parentid") private String Parentid; @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY) @JoinColumn(name="Parentid" referencedColumnName="Parentid") …
1
vote
1 answer

How to trigger a saveAll on child objects in one-to-many relationship using Spring JPA?

For background, I am trying to speed up database inserts by enabling hibernate.jdbc.batch_size property. I have added this property, but it appears that the inserts were still not optimized. I have researched and found that the batch_size property…
1
vote
1 answer

Can we create both parent and child in a row in OneToMany unidirectionnal relationship using Spring JPA?

I'm trying to understand how Spring JPA works in creating (POST http action) resources under relationships (@OneToMany). I have 2 simples classes, Product and Comment. One productis related to many comments. Product class : @Entity @Table(name =…
1
vote
1 answer

Hibernate: map last row of a @OneToMany relation

I have a relation between element and its names. All historical names as well as the current one are located in table "element_name" that has field "created". The row last created is the current name of the element. How could I map the current name…
Mikk
  • 551
  • 4
  • 9
1
vote
1 answer

JPA join query on one-to-many association

I have a one-to-many relationship with Customer and Order entity. This is of a composition relationship. I want to write a query to find out if there is a matching Order with the given orderId and the customerId. This method should be in the…
zilcuanu
  • 3,451
  • 8
  • 52
  • 105
1
vote
1 answer

Unable to find column with logical name in JPA Springboot

There are two tables. Address inside Hotel. I have already mentioned OneToMany relation. But compiler throwing error. Error creating bean with name 'entityManagerFactory' defined in class path…
Mr.Shah
  • 61
  • 7
1
vote
1 answer

deleted object would be re-saved by cascade (remove deleted object from associations) : Error while trying to attach a child from one parent to other

In an application using hibernate 5.0.9 have nested parent child relation where parent is relation owner respresented as below. Tables: - ParentEntity @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name =…
1
vote
0 answers

How to retrieve primary key id from Jcombobox in java with hibernate which has one to many relation?

I have entity items and units, items are related one to many in the unit, I have difficulty entering data into items, where items need a primary key on the unit, while I don't understand how Jcombobox works in getting primary keys or IDs. item class…
1
vote
0 answers

JPA(Hibernate) UPDATE problem using JpaRepository.save() method in Mapping Relationship

Floor.java @Entity @Getter @Setter @AllArgsConstructor @Table(name = "floors") @Builder public class Floor { @Id @Column(name = "floor_id", nullable = false) private String floorId; @Column(name = "floor_name", nullable = false) …