Skip to content

Instantly share code, notes, and snippets.

@donovanmuller
Created June 30, 2014 15:58
Show Gist options
  • Save donovanmuller/bd61d854ebcd4b26bd68 to your computer and use it in GitHub Desktop.
Save donovanmuller/bd61d854ebcd4b26bd68 to your computer and use it in GitHub Desktop.
SO - 24489963 - mappedBy
[main] DEBUG so.services.OrderServiceTest - >>> Persisting original SO question Order
Hibernate:
insert
into
WAITERENTITY
(id, name)
values
(null, ?)
Hibernate:
insert
into
ORDERENTITY
(orderNumber, finalized, sumOfMoney, waiter_id)
values
(null, ?, ?, ?)
[main] DEBUG so.services.OrderServiceTest - <<<Persisted original SO question Order
[main] DEBUG so.services.OrderServiceTest - >>> Adding OrderEntity maintaining both relationships
Hibernate:
select
waiterenti0_.id as id1_1_0_,
waiterenti0_.name as name2_1_0_,
orders1_.waiter_id as waiter_i4_1_1_,
orders1_.orderNumber as orderNum1_0_1_,
orders1_.orderNumber as orderNum1_0_2_,
orders1_.finalized as finalize2_0_2_,
orders1_.sumOfMoney as sumOfMon3_0_2_,
orders1_.waiter_id as waiter_i4_0_2_
from
WAITERENTITY waiterenti0_
left outer join
ORDERENTITY orders1_
on waiterenti0_.id=orders1_.waiter_id
where
waiterenti0_.id=?
Hibernate:
insert
into
ORDERENTITY
(orderNumber, finalized, sumOfMoney, waiter_id)
values
(null, ?, ?, ?)
[main] DEBUG so.services.OrderServiceTest - >>> Adding OrderEntity without maintaining inverse side
Hibernate:
select
waiterenti0_.id as id1_1_0_,
waiterenti0_.name as name2_1_0_,
orders1_.waiter_id as waiter_i4_1_1_,
orders1_.orderNumber as orderNum1_0_1_,
orders1_.orderNumber as orderNum1_0_2_,
orders1_.finalized as finalize2_0_2_,
orders1_.sumOfMoney as sumOfMon3_0_2_,
orders1_.waiter_id as waiter_i4_0_2_
from
WAITERENTITY waiterenti0_
left outer join
ORDERENTITY orders1_
on waiterenti0_.id=orders1_.waiter_id
where
waiterenti0_.id=?
Hibernate:
insert
into
ORDERENTITY
(orderNumber, finalized, sumOfMoney, waiter_id)
values
(null, ?, ?, ?)
Hibernate:
select
waiterenti0_.id as id1_1_0_,
waiterenti0_.name as name2_1_0_,
orders1_.waiter_id as waiter_i4_1_1_,
orders1_.orderNumber as orderNum1_0_1_,
orders1_.orderNumber as orderNum1_0_2_,
orders1_.finalized as finalize2_0_2_,
orders1_.sumOfMoney as sumOfMon3_0_2_,
orders1_.waiter_id as waiter_i4_0_2_
from
WAITERENTITY waiterenti0_
left outer join
ORDERENTITY orders1_
on waiterenti0_.id=orders1_.waiter_id
where
waiterenti0_.id=?
@Entity
@XmlRootElement
@Table(name = "WAITERENTITY")
public class WaiterEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@OneToMany(mappedBy = "waiter", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
private List<OrderEntity> orders Z= new ArrayList<>();
...
}
@donovanmuller
Copy link
Author

Same test as https://gist.github.com/donovanmuller/d9b06edc2bfb00e0fe64#file-orderservicetest-java

Note from line 36 compared to the non mappedBy version from line 36 that there is no extra update for the waiter_id on OrderEntity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment