I have an entity Customer
with an @ElementCollection
annotation:
@Entity
@Table(name = "customer")
public class Customer {
@Id
@Column(name = "id")
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
@ElementCollection
@CollectionTable(name = "customer_alias", joinColumns = @JoinColumn(name = "customer_id") )
@Column(name = "alias")
private List<String> aliases;
}
The table customer_alias
contains a few rows when I start my app. In my code I have a loop that iterates the aliases:
for(String alias: customer.getAliases()) { ... }
Strangely, right after this line I see in the log these 2 lines:
Hibernate: select aliases0_.customer_id as cus1_3_0_, aliases0_.aliase as ali2_0_0_ from customer_alias aliases0_ where aliases0_.customer_id=?
Hibernate: delete from customer_alias where customer_id=?
Of course - after the 'delete' line the data is deleted from the DB and I can't figure out why. There's no where in my code where I call delete and it happens right after the for loop. It looks like when I call getAliases()
it deletes the table.